Advertisement
Guest User

Test case for sort issue in DataGrid

a guest
Aug 31st, 2010
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.12 KB | None | 0 0
  1. <Window x:Class="DataGridTest5.MainWindow"
  2.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.        xmlns:local="clr-namespace:DataGridTest5"
  5.        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
  6.        Title="Test" Height="200" Width="650">
  7.   <Window.Resources>
  8.     <!-- DataGrid source, as a CollectionViewSource to allow for sorting and/or filtering -->
  9.     <CollectionViewSource x:Key="Players"
  10.                          Source="{Binding ElementName=lstLevel, Path=SelectedItem.Players}">
  11.       <CollectionViewSource.SortDescriptions>
  12.         <scm:SortDescription PropertyName="Name" />
  13.       </CollectionViewSource.SortDescriptions>
  14.     </CollectionViewSource>
  15.   </Window.Resources>
  16.   <Grid>
  17.     <Grid.ColumnDefinitions>
  18.       <ColumnDefinition Width="120" />
  19.       <ColumnDefinition Width="250" />
  20.       <ColumnDefinition Width="*" />
  21.     </Grid.ColumnDefinitions>
  22.  
  23.     <!-- Level selection -->
  24.     <ScrollViewer Grid.Column="0">
  25.       <ListBox Name="lstLevel"
  26.               DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True" />
  27.     </ScrollViewer>
  28.  
  29.     <!-- Players data, with sort on the Name column -->
  30.     <StackPanel Grid.Column="1">
  31.       <Label>DataGrid:</Label>
  32.       <DataGrid Name="lstPlayers" AutoGenerateColumns="False"
  33.                CanUserSortColumns="False"
  34.                ItemsSource="{Binding Source={StaticResource Players}}">
  35.         <DataGrid.Columns>
  36.           <DataGridTextColumn Header="Name"
  37.                              Binding="{Binding Path=Name, Mode=TwoWay}"
  38.                              Width="*" />
  39.           <DataGridTextColumn Header="Age"
  40.                              Binding="{Binding Path=Age, Mode=TwoWay}"
  41.                              Width="80">
  42.           </DataGridTextColumn>
  43.         </DataGrid.Columns>
  44.       </DataGrid>
  45.     </StackPanel>
  46.  
  47.     <StackPanel Grid.Column="2">
  48.       <Label>ListBox:</Label>
  49.       <ListBox ItemsSource="{Binding Source={StaticResource Players}}" DisplayMemberPath="Name" />
  50.     </StackPanel>
  51.   </Grid>
  52. </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement