I am following MVVM in this project.
I have a datagrid WPF,
ItemsSource is (ItemsSource="{Binding Documents}")tied to ObservableCollection<Document>,
SelectedItem is (SelectedItem="{Binding CurrentDocument, Mode=TwoWay}")attached to WorkQueueDocument,
I also used interaction triggers to double-click to load the selected document into a new WIndow file.
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding ShowViewerCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
I have defined / linked the columns of my datagrid with the corresponding attributes of the WorkQueueDocument class.
<DataGrid.Columns>
<DataGridTextColumn Width="Auto"
MinWidth="100"
Header="Name"
Binding="{Binding Name}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="2,0,0,0" />
<Setter Property="ToolTip" Value="{Binding Name}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.ColumnHeaderStyle>
</DataGrid.ColumnHeaderStyle>
I have to load the document when the user selects a row (document) in the grid - for this property, CurrentDocument is defined as follows:
public WorkQueueDocument CurrentDocument
{
get
{
return this.currentDocument;
}
set
{
if (this.currentDocument != value)
{
this.currentDocument = value;
this.OnPropertyChanged("CurrentDocument");
this.IsDocumentSelected = true;
if (!IsLoading && this.currentDocument != null)
{
IsLoading = true;
LoadDocumentBackgroundWorker();
}
if (this.currentDocument == null)
{
this.IsDocumentSelected = false;
}
}
}
}
, "" , , "" - .
xaml <DataGrid.Columns>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="DeleteBatch"
Content="Delete"
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.DeleteCommand}"
CommandParameter="Delete"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
DeleteCommand . ,
datagrid
ItemsSource="{Binding Documents}"
, datagrid
<Button Name="Delete"
Content="Delete"
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.DeleteCommand}"
CommandParameter="Delete">
. - ( "" ) " SelectedItem",
DeleteCommand ( ). SelectedItem ', deleteCommand ( ).
( ) ** DeleteCommand , () ( ) **
googled - , , .
, .
, , .
P.S:
1. WPF,.Net 4.0 MVVM
- , . [ ]