Reputation: 3731
I am using the WPF Toolkit's DateTimeUpDown inside a DataGridTemplateColumn (It isnt in the regular release, it is only available in the latest code changes). I have bound it to a DateTime property from one of my classes, where the DataGrid is in turn, bound to an ObservableCollection of said classes. Every column in the DataGrid apart from the one that includes the DateTimeUpDown control. My class implements INotifyPropertyChanged as the ObservableCollection itself does. Also, i override the ObservableCollection's Insert so i hook each of the added objects' NotifyPropertyChanged Delegate so i update the backend database with each change. My problem is... the delegate never gets fired even though i change the date using the control. Any Ideas?
XAML:
<Window x:Class="LDary.Deudas"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:t="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
Title="Deudas" Height="300" Width="300" Name="WinDeudas" Closing="WinDeudas_Closing">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Name="Lista" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=WinDeudas, Path=SDeudas}"
GridLinesVisibility="None" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" IsTextSearchEnabled="True" IsReadOnly="False"
AlternatingRowBackground="#FFF0F0F0" BorderBrush="#FFF0F0F0"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" IsReadOnly="True"/>
<DataGridTextColumn Header="Nombre" Binding="{Binding Nombre}" Width="*" IsReadOnly="True"/>
<DataGridTextColumn Header="Cedula" Binding="{Binding Cedula}" IsReadOnly="True"/>
<DataGridTextColumn Header="Telefono" Binding="{Binding Telefono}" IsReadOnly="True"/>
<DataGridTextColumn Header="Caracteristica" Binding="{Binding Caracteristica}" IsReadOnly="True"/>
<DataGridTextColumn Header="Fecha" Binding="{Binding Fecha}" IsReadOnly="True"/>
<!--<DataGridTextColumn Header="Fecha Limite" Binding="{Binding FechaPago}" />-->
<DataGridTemplateColumn Header="Fecha Limite" IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<t:DateTimeUpDown Value="{Binding FechaPago}" Format="LongDate"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Valor" Binding="{Binding Valor}" />
</DataGrid.Columns>
</DataGrid>
<TextBox Name="txtBusqueda" Grid.Row="1" Padding="0,5"/>
<Button Name="BtnGuardar" Grid.Row="2" Padding="0,5" Content="Guardar Cambios" Click="BtnGuardar_Click"/>
</Grid>
Code:
public new void Insert(int index, Deuda Item)
{
Item.PropertyChanged += new PropertyChangedEventHandler(PropertyChangedHandler);
base.Insert(index, Item);
}
Thanks in advance.
Upvotes: 2
Views: 2180
Reputation: 1012
Add
UpdateSourceTrigger=PropertyChanged
to your DateTimeUpDown control binding, like this
<t:DateTimeUpDown Value="{Binding FechaPago, UpdateSourceTrigger=PropertyChanged}" Format="LongDate"/>
Upvotes: 2
Reputation:
I think the problem is that you have to fire the PropertyChanged event of the underlying INotifyPropertyChanged DataContext object by your own:
private DateTime _fechaPago;
public DateTime FechaPago
{
get { return this._fechaPago; }
set
{
this._fechaPago = value;
this.OnPropertyChanged("FechaPago");
}
}
protected void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
The DataContext object must tell that one of its properties changed.
Upvotes: 0