EventTrigger无法将中继命令绑定到DatePicker DateChanged事件

时间:2017-09-21 23:53:45

标签: c# mvvm uwp

我正在使用MVVM灯处理UWP应用程序,并且在尝试将视图模型中的中继命令绑定到DatePicker控件的DateChanged事件时遇到了问题。

查看

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <DatePicker Date="{Binding GameDay}" DateChanged="{Binding ChangeGameDay}"/>
</Grid>

视图模型

public class ScheduleViewModel : ViewModelBase
{
    private readonly INavigationService _navigationService;

    public ScheduleViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
    }

    private DateTime gameDay;
    public DateTime GameDay
    {
        get { return gameDay; }
        set
        {
            gameDay = value;
            RaisePropertyChanged(() => GameDay);
        }
    }        

    private RelayCommand changeGameDay;
    public RelayCommand ChangeGameDay
    {
        get
        {
            return changeGameDay
            ?? (changeGameDay = new RelayCommand(
                () =>
                {
                    // TODO: Change game day data
                }));
        }
    }
}

尝试编译应用程序时出现对象引用错误

  

对象引用未设置为对象的实例C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Community \ MSBuild \ Microsoft \ WindowsXaml \ v15.0 \ 8.2 \ Microsoft.Windows.UI.Xaml。 Common.targets 266

如果从视图中删除DateChanged事件处理程序,则此错误消失。我应该采用不同的方式绑定事件吗?

0 个答案:

没有答案