(WInUI 3)DatePicker SelectedDate x:Bind和Binding是不同的结果??x:Bind => SelectedDate为null Binding => SelectedDate为1923-1-1
结果图像:
怎么办让绑定也为null?
验证码:
<DatePicker SelectedDate="{x:Bind vm.MyDate, Mode=TwoWay}"/>
<StackPanel DataContext="{x:Bind vm}">
<DatePicker SelectedDate="{Binding MyDate}"/>
</StackPanel>
public class MyTable : ObservableObject
{
private DateTimeOffset? _mydate;
public DateTimeOffset? MyDate
{
get => _mydate;
set => SetProperty(ref _mydate, value);
}
}
public sealed partial class MainWindow : Window
{
MyTable vm = new MyTable();
public MainWindow() { this.InitializeComponent(); }
}
1条答案
按热度按时间xdyibdwo1#
看起来
Binding
没有传递null
的值,而是将其转换为某个默认值。这可能是因为DateTimeOffset
是struct
。无论如何,这里有一个创建自定义控件的解决方法:
它同时适用于
Binding
和x:Bind
: