mersadk
mersadk

Reputation: 337

DatePicker is OneWay, but I need TwoWay

I have following DataGrid in wpf.

<DataGrid AutoGenerateColumns="False" Grid.Row="1" Name="adsGrid" ItemsSource="{Binding Path=Ads}" CanUserAddRows="False" CanUserDeleteRows="False" SelectionChanged="adsGrid_SelectionChanged">
            <DataGrid.Columns>
                <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" IsReadOnly="True" />
                <DataGridTextColumn Header="File" Binding="{Binding Path=FileName}" IsReadOnly="True" />                
                <DataGridTemplateColumn Header="Expiration date" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DatePicker SelectedDate="{Binding Path=ExpirationDate}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="Info" Width="100*" Binding="{Binding Path=Info}" />
            </DataGrid.Columns>
        </DataGrid>

Problem is that DateTime picker won't update related object but will read value from it. I've tried adding Mode=TwoWay but it didn't help. Other properties are updated properly.

Upvotes: 1

Views: 2656

Answers (1)

Paul Stovell
Paul Stovell

Reputation: 32745

To debug this I would try:

  1. Check the ExpirationDate property a DateTime (not a nullable or DateTimeOffset?)
  2. Setting UpdateSourceTrigger=PropertyChanged
  3. Adding a converter, and seeing if the converter is called

Upvotes: 5

Related Questions