I created a button column as a template column in a WPF datagrid. When you press the button it sets the button content to the current date.
<DataGridTemplateColumn Header="Date In Source">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="BtnDateInSource" Click="DateButton" Style="{StaticResource ReceiveWorkButton}" ></Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<Style TargetType="{x:Type Button}" x:Key="ReceiveWorkButton" >
<Setter Property="Background" Value="Green"/>
<Setter Property="Content" Value="{Binding DateInSource}"/>
<Setter Property="IsEnabled" Value="False"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DateInSource}" Value="{x:Null}" >
<Setter Property="Background" Value="#A3BF3B" />
<Setter Property="Content" Value="Receive Work" />
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
The current problem is that since it is a template column I can't seem to bind it to the datasource (MVVM).
So the user presses the button, and it changes the button text to the current date/time. I now want to write that back to the database.
My MVVM observable collection is InspectionStatus
in class SourceInspection
.
I would like to do it in XAML but maybe it has to be done with INotifyPropertyChanged
?
DatagridContext: Code Behind:
System.Windows.Data.CollectionViewSource SourceViewSource =
((System.Windows.Data.CollectionViewSource)
(this.FindResource("SourceViewSource")));
_context.SourceInspections.Load();
SourceViewSource.Source = _context.SourceInspections.Local;
I think I figured it out, used this... updating wpf datagrid on button click
Regards K.