WPF List Box

ItemTemplate – DataTemplate

            <ListBox ItemsSource="{Binding}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel.Resources>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Margin" Value="0, 0, 5, 0" />
                                    </Style>
                                </StackPanel.Resources>
                                <TextBlock Text="{Binding Path=ID}" />
                                <TextBlock Text="{Binding Path=Task1}" />
                                <TextBlock Text="{Binding Path=PercentComplete}" />
                            </StackPanel>
                            <TextBlock Text="Resource names here" Margin="50, 0, 0, 0" />
                            <!--<TextBlock Text="{Binding Path=ResourceName}" Margin="50, 0, 0, 0" />-->
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Sorting

        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

        <CollectionViewSource x:Key="taskViewSource" d:DesignSource="{d:DesignInstance my:Task, CreateList=True}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="CompleteFlag"
                                     Direction="Descending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

 

Style DataTrigger

            <ListBox ItemsSource="{Binding}">
                <ListBox.Resources>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=CompleteFlag}"
                                         Value="True">
                                <Setter Property="Background"
                                        Value="Yellow" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.Resources>
...
            </ListBox>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: