How do I filter out duplicate entries in my list when bound to a data source?

The fact that you have duplicate entries probably suggests that you are binding to the wrong data source. But, in any case, there are possibly valid scenarios where this is necessary. Here is a solution. One way is to group the list by name using CollectionViewSource and then bind the Groups to the ListBox. Here is some code: (for better code formatting, look at this thread: Distinct Value Filter For ListBox If you Contracts collection is like this: [C#] public class Contracts : List { public Contracts() { this.Add(new Contract() { ContractKey = ‘1’, Name = ‘John’ }); this.Add(new Contract() { ContractKey = ‘2’, Name = ‘Bill’ }); this.Add(new Contract() { ContractKey = ‘3’, Name = ‘Bill’ }); } } public class Contract { public string ContractKey { get; set; } public string Name { get; set; } } Then you can use the CollectionViewSource to bind to it and group the colelction by Name as follows: [XAML] This will render the listbox the way you want – ignoring the duplicate names. You can then interpret the selected item as follows: [XAML] private void lb_SelectionChanged(object sender, SelectionChangedEventArgs e) { CollectionViewGroup groupSelected = ((CollectionViewGroup)e.AddedItems[0]); string name = groupSelected.Name; // These contain the items within the group //groupSelected.Items; }

How do I execute 2 animations in parallel?

You can do so by first making the 2 animations a child of a single storyboard as follows: <BeginStoryboard> <Storyboard x:Name=’Animation’> <Storyboard x:Name=’FadeInStoryboard’/> <Storyboard x:Name=’FadeOutStoryboard’/> </Storyboard </BeginStoryboard>

How do I create in-line event handlers?

Here are some examples: Example 1: animation.Completed += delegate { // Start the other animation after the end of the previous animation. index++; if (lstDefinitions.Count > index) this.PerformAnimations(index, lstDefinitions); }; Example 2: label.MouseDown += (sender, e) => { Console.WriteLine(‘MouseDown:{0}’, e.OriginalSource); //Not clear why this is needed, but I guess this can effectively bypass // any attempt from the parent control to capture the mouse inside MouseDown handler. e.Handled = true; };

How do I create a single template and resue it for multiple columns in a ListView?

Here is a solution: [XAML] <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ xmlns:sys=’clr-namespace:System;assembly=mscorlib’> <Page.Resources> <XmlDataProvider x:Key=’CharacterData’> <x:XData> <Data xmlns=”> <Character First=’Bart’ Last=’Simpson’ Gender=’M’/> <Character First=’Homer’ Last=’Simpson’ Gender=’M’/> <Character First=’Lisa’ Last=’Simpson’ Gender=’F’/> <Character First=’Maggie’ Last=’Simpson’ Gender=’F’/> <Character First=’Marge’ Last=’Simpson’ Gender=’F’/> </Data> </x:XData> </XmlDataProvider> <DataTemplate x:Key=’LVTSimpleText’> <Border Width=’Auto’ Height=’Auto’ BorderBrush=’#FF000000′ BorderThickness=’0,0,2,2′> <TextBox Width=’Auto’ Height=’Auto’ Text='{Binding Value}’ TextWrapping=’Wrap’/> </Border> </DataTemplate> </Page.Resources> <ListView ItemsSource='{Binding Source={StaticResource CharacterData}, XPath=Data/Character}’> <ListView.View> <GridView> <GridViewColumn Header=’First Name’> <GridViewColumn.CellTemplate> <DataTemplate> <ContentControl Content='{Binding XPath=@First}’ ContentTemplate='{StaticResource LVTSimpleText}’ /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header=’Last Name’> <GridViewColumn.CellTemplate> <DataTemplate> <ContentControl Content='{Binding XPath=@Last}’ ContentTemplate='{StaticResource LVTSimpleText}’ /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header=’Gender’> <GridViewColumn.CellTemplate> <DataTemplate> <ContentControl Content='{Binding XPath=@Gender}’ ContentTemplate='{StaticResource LVTSimpleText}’ /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> </Page>

How do I color the bg of my ListView in GridView mode based on a ‘search’ textbox where the user can enter search text?

This is kind of how Firefox lets you search texts – as you type in the search box the matching text all get highligted automatically. You can use this solution for other templatized controls as well. (For better formatting, take a look at this thread: How to color particular cell of the grid view?) [XAML] <Window x:Class=’SDKSample.Window1′ xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ Loaded=’OnLoad’ xmlns:ds=’clr-namespace:SDKSample’> <Window.Resources> <ds:MyBGConverter x:Key=’myBGConverter’></ds:MyBGConverter> <ObjectDataProvider x:Key=’EmployeeInfoDataSource’ ObjectType='{x:Type ds:myEmployees}’/> <!–Repeat this for all columns where you want this to happen–> <DataTemplate x:Key=’myCellTemplateFN’> <DockPanel> <TextBlock Foreground=’Green’ HorizontalAlignment=’Center’> <TextBlock.Text> <Binding Path=’FirstName’/> </TextBlock.Text> <TextBlock.Background> <MultiBinding Converter='{StaticResource myBGConverter}’> <MultiBinding.Bindings> <Binding ElementName=’searchTB’ Path=’Text’ /> <Binding RelativeSource='{RelativeSource Self}’></Binding> </MultiBinding.Bindings> </MultiBinding> </TextBlock.Background> </TextBlock> </DockPanel> </DataTemplate> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height=’50’/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock Grid.Row=’0′ Grid.Column=’0′ FontSize=’14’ HorizontalAlignment=’Center’> ListView created with XAML </TextBlock> <StackPanel Grid.Row=’1′ Grid.Column=’0′ HorizontalAlignment=’Center’> <ListView ItemsSource='{Binding Source= {StaticResource EmployeeInfoDataSource}}’ > <ListView.View> <GridView AllowsColumnReorder=’true’ ColumnHeaderToolTip=’Employee Information’> <GridViewColumn CellTemplate='{StaticResource myCellTemplateFN}’ Header=’First Name’ Width=’100’/> <GridViewColumn DisplayMemberBinding= ‘{Binding Path=LastName}’ Header=’Last Name’ Width=’100’/> <GridViewColumn DisplayMemberBinding= ‘{Binding Path=EmployeeNumber}’ Header=’Employee No.’ Width=’100’/> </GridView> </ListView.View> </ListView> <StackPanel Orientation=’Horizontal’> <TextBlock>Enter Search String Here:</TextBlock> <TextBox x:Name=’searchTB’ MinWidth=’100′ Width=’150′></TextBox> </StackPanel> </StackPanel> </Grid> </Window> And add this to your code-behind: [C#] public class MyBGConverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { TextBlock lvi = (TextBlock)values[1]; string filter = (string)values[0]; if (filter != String.Empty && lvi.Text.ToLower().Contains(filter.ToLower())) { return Brushes.Aqua; } else return Brushes.White; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class EmployeeInfo { private string _firstName; private string _lastName; private string _employeeNumber; public string FirstName { get {return _firstName;} set {_firstName = value;} } public string LastName { get {return _lastName;} set {_lastName = value;} } public string EmployeeNumber { get {return _employeeNumber;} set {_employeeNumber = value;} } public EmployeeInfo(string firstname, string lastname, string empnumber) { _firstName = firstname; _lastName = lastname; _employeeNumber = empnumber; } } public class myEmployees : ObservableCollection { public myEmployees() { Add(new EmployeeInfo(‘Jesper’, ‘Aaberg’, ‘12345’)); Add(new EmployeeInfo(‘Dominik’, ‘Paiha’, ‘98765’)); Add(new EmployeeInfo(‘Yale’, ‘Li’, ‘23875’)); Add(new EmployeeInfo(‘Muru’, ‘Subramani’, ‘49392’)); } }