I have two WPF elements bound to the same ObservableCollection. One is a Datagrid and one is a ListBox. When the Datagrid is used to sort on a column (using the built-in column headers) the action puts the items in the listbox into the same order. In other words, it seems that the sorting action in the Datagrid affects the ordering of the underlying collection. Is there a way to disable this behavior?
Here is the XAML for the Datagrid:
<DataGrid
IsReadOnly="True">
>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding no}" >
<DataGridTextColumn.Header>
<TextBlock>
File<LineBreak/>No.
</TextBlock>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Header="Name"
Binding="{Binding fileName}" />
<DataGridTextColumn Binding="{Binding channels}" >
<DataGridTextColumn.Header>
<TextBlock TextAlignment="Center">
Channels<LineBreak/>[#]
</TextBlock>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
and the Listbox:
<ListBox
SelectedIndex="{Binding fileListSelectedIndex}"
SelectedItem="{Binding fileListSelectedItem}"
>
<ListBox.Resources>
<DataTemplate DataType="{x:Type local:FileListItem}">
<TextBlock Text="{Binding Path=fileName}"/>
</DataTemplate>
</ListBox.Resources>
</ListBox>
finally, the binding code:
filelist.ItemsSource = vm.fileList;
multiFileParamGrid.ItemsSource = vm.fileList;