Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="DataGridTest5.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:DataGridTest5"
- xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
- Title="Test" Height="200" Width="650">
- <Window.Resources>
- <!-- DataGrid source, as a CollectionViewSource to allow for sorting and/or filtering -->
- <CollectionViewSource x:Key="Players"
- Source="{Binding ElementName=lstLevel, Path=SelectedItem.Players}">
- <CollectionViewSource.SortDescriptions>
- <scm:SortDescription PropertyName="Name" />
- </CollectionViewSource.SortDescriptions>
- </CollectionViewSource>
- </Window.Resources>
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="120" />
- <ColumnDefinition Width="250" />
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <!-- Level selection -->
- <ScrollViewer Grid.Column="0">
- <ListBox Name="lstLevel"
- DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True" />
- </ScrollViewer>
- <!-- Players data, with sort on the Name column -->
- <StackPanel Grid.Column="1">
- <Label>DataGrid:</Label>
- <DataGrid Name="lstPlayers" AutoGenerateColumns="False"
- CanUserSortColumns="False"
- ItemsSource="{Binding Source={StaticResource Players}}">
- <DataGrid.Columns>
- <DataGridTextColumn Header="Name"
- Binding="{Binding Path=Name, Mode=TwoWay}"
- Width="*" />
- <DataGridTextColumn Header="Age"
- Binding="{Binding Path=Age, Mode=TwoWay}"
- Width="80">
- </DataGridTextColumn>
- </DataGrid.Columns>
- </DataGrid>
- </StackPanel>
- <StackPanel Grid.Column="2">
- <Label>ListBox:</Label>
- <ListBox ItemsSource="{Binding Source={StaticResource Players}}" DisplayMemberPath="Name" />
- </StackPanel>
- </Grid>
- </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement