I am using a DataGrid
to present data from a List<VideoFile>
containing objects with mostly string properties describing a video file like title, runtime, quality etc. I want to be able to arrange and edit displayed data via the DataGrid
and refresh DataGrid
content on the fly. I'm new to WPF so i've read multiple threads on the topic and i am pretty confused what is the best (least complex, fastest) way to achieve this.
My current implementation:
GlobalVariables.List1 = Program.LoadFromXML(GlobalVariables.DatabaseLocation);
GlobalVariables.itemCollectionViewSource = (CollectionViewSource)(FindResource("ItemCollectionViewSource"));
GlobalVariables.itemCollectionViewSource.Source = GlobalVariables.List1;
XAML:
<Window.Resources>
<CollectionViewSource
x:Key="ItemCollectionViewSource"
CollectionViewType="ListCollectionView"/>
</Window.Resources>
<DataGrid x:Name="LibraryDisplay"
Margin="10,10,10,0"
Height="527" Width="715"
ItemsSource="{Binding}"
DataContext="{StaticResource ItemCollectionViewSource}"
AutoGenerateColumns="True"
HorizontalAlignment="Left"
VerticalAlignment="Top"
IsReadOnly="False"
SelectionChanged="DataGrid_SelectionChanged"
CellEditEnding="DataGrid_CellEditEnding"
/>
AutoGenerateColums is set temporarily. Here is a part of how it looks: