Wpf 日期选择器是单向的,但我需要双向的
我有以下wpf中的DataGridWpf 日期选择器是单向的,但我需要双向的,wpf,xaml,data-binding,datetimepicker,Wpf,Xaml,Data Binding,Datetimepicker,我有以下wpf中的DataGrid <DataGrid AutoGenerateColumns="False" Grid.Row="1" Name="adsGrid" ItemsSource="{Binding Path=Ads}" CanUserAddRows="False" CanUserDeleteRows="False" SelectionChanged="adsGrid_SelectionChanged"> <DataGrid.Columns&
<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>
问题是DateTime选择器不会更新相关对象,但会从中读取值。我尝试添加Mode=TwoWay,但没有效果。其他属性已正确更新。要调试此属性,我将尝试:
DateTime
(不是可为null或DateTimeOffset?)UpdateSourceTrigger=PropertyChanged
要调试此功能,我将尝试:
DateTime
(不是可为null或DateTimeOffset?)UpdateSourceTrigger=PropertyChanged
当您在调试应用程序时更改datepicker的值时,输出窗口是否会显示任何信息?可空性可能会导致错误。检查
DatePicker.SelectedDate
和ExpirationDate
属性的类型是否匹配。如果您使用的转换器介于两者之间,请确保其双向可转换。还可以在绑定中添加双向模式。@AngelWPF它们都是DateTime?没有mersadkDatePicker。SelectedDate
可为null
。我不确定您的到期日期属性是什么。它可为空吗?如果是这样,没有转换器的双向绑定应该可以正常工作。@AngelWPF ExpirationDate是“DateTime”,可以为空。但是我可以理解为什么我之前的文章让人困惑:)当你在调试应用程序时更改datepicker的值时,输出窗口会说些什么吗?可空性会导致错误。检查DatePicker.SelectedDate
和ExpirationDate
属性的类型是否匹配。如果您使用的转换器介于两者之间,请确保其双向可转换。还可以在绑定中添加双向模式。@AngelWPF它们都是DateTime?没有mersadkDatePicker。SelectedDate
可为null
。我不确定您的到期日期属性是什么。它可为空吗?如果是这样,没有转换器的双向绑定应该可以正常工作。@AngelWPF ExpirationDate是“DateTime”,可以为空。但我能理解为什么我以前的帖子让人困惑:)它是可以为空的,这有问题吗?我试过使用converter,它是在从对象转换到wpf时调用的,但不是在相反的方向。解决方案是将UpdateSourceTrigger=PropertyChanged添加到bindingIt为nullable,这有问题吗?我试过使用converter,它是在从对象转换到wpf时调用的,但不是相反的方向