pimp my listbox rainer stropek cubido business solutions gmbh

Post on 28-Mar-2015

217 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Pimp My Listbox

Rainer Stropekcubido business solutions gmbh

enter the the presentation name in the footer field 5 18.10.2007

Window

StackPanel

TextBlock

TextBox

ElementBaum

Logischer undBorder

AdornerDecorator

AdornerLayer

ContentPresenter

String

String

... (ScrollViewer, Grid, Rectangle, ScrollBar, etc.)

StackPanel

TextBlock

TextBox

Window

VISUELLER BAUM

[ContentPropertyAttribute("Items")] [LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)] [StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=typeof(FrameworkElement))] public class ItemsControl : Control, IAddChild

<ListBox> <TextBlock Text="MyTextBlock" /> <Button Content="My Button" /> <Rectangle Width="30" Height="10" Fill="Gray" /> <sys:String>Ein Text!</sys:String> <sys:Random /> </ListBox>

DEMO...Füllen einer Listbox im XAML-Code

<Page ...xmlns:sys="clr-namespace:System;assembly=mscorlib"xmlns:sysio="clr-namespace:System.IO;assembly=mscorlib"Margin="10"> <Page.Resources> <ObjectDataProvider ObjectType="{x:Type sysio:DirectoryInfo}" MethodName="GetFiles" x:Key="Files"> <ObjectDataProvider.ConstructorParameters> <sys:String>[...]\Images</sys:String> </ObjectDataProvider.ConstructorParameters> </ObjectDataProvider> </Page.Resources>

<ListBox ItemsSource="{Binding Source={StaticResource Files}}" /></Page>

DEMO...Füllen einer Listbox mit Data Binding

Resourcen

<ListBox ..."> <ListBox.Resources> <Style TargetType="ListBox"> ... </Style> </ListBox.Resources></ListBox>

Lokale Resourcen

<Page.Resources> <Style TargetType="ListBox"> ... </Style> <Style TargetType="ListBoxItem"> ... </Style></Page.Resources>

Resourcen in Windows oder Pages

<Application.Resources> <Style TargetType="ListBox"> ... </Style> ...</Application.Resources>

Resourcen in app.xaml

Styles

<ListBox Grid.Column="0" Grid.Row="1"ItemsSource="{Binding Source={StaticResource Files}}"> <ListBox.Resources> <Style TargetType="ListBox"> <Setter Property="Background" Value="LightGray" /> <Setter Property="FontSize" Value="11" /> </Style> </ListBox.Resources></ListBox>

DEMO...Styling der Listbox

Templates

FrameworkTemplate

DataTemplateControlTemplat

eItemsPanelTe

mplate

Data Trigger

<DataTemplate DataType="{x:Type sysio:FileInfo}"> ... <DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=IsReadOnly}" Value="True"> <Setter Property="TextBlock.Foreground" Value="Gray" /> <Setter Property="TextBlock.FontStyle" Value="Italic" /> </DataTrigger> </DataTemplate.Triggers></DataTemplate>

DEMO...Data Template mit Data Trigger

Control Template

<Style TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Ellipse Fill="{StaticResource ButtonBrush}" Stroke="DarkGray" /> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

DEMO...Control Template mit Trigger

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel>

<TextBlock Text="MyTextBlock" /> <Button Content="My Button" /> <Rectangle Width="30" Height="10" Fill="Gray" /> <sys:String>Ein Text!</sys:String> <sys:Random /> ...</ListBox>

27

DEMO…ListBox mit WrapPanel statt StackPanel

DEMO...ItemsPanelTemplate, individuelles Panel

Custom Controls

Logik

Design

DEMO...Custom Control

enter the the presentation name in the footer field 32 18.10.2007

r.stropek@cubido.at

oder rainer@software-architects.at

Karin Huber, Rainer StropekSoftware Architects

top related