Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将MVVM命令绑定到UWP中的时间选择器控制_C#_Xaml_Mvvm_Win Universal App_Template10 - Fatal编程技术网

C# 将MVVM命令绑定到UWP中的时间选择器控制

C# 将MVVM命令绑定到UWP中的时间选择器控制,c#,xaml,mvvm,win-universal-app,template10,C#,Xaml,Mvvm,Win Universal App,Template10,我在XAML页面上使用TimePicker控件,并尝试对相应的ViewModel中的更改做出反应。我在我的页面中添加了Xaml.Interactivity和Xaml.Interactivity.Core命名空间,以便在调用TimeChanged事件后使用Behaviors SDK触发命令 <!-- XAML Namespaces --> xmlns:interact="using:Microsoft.Xaml.Interactivity" xmlns:interactcore="us

我在XAML页面上使用
TimePicker
控件,并尝试对相应的
ViewModel
中的更改做出反应。我在我的页面中添加了
Xaml.Interactivity
Xaml.Interactivity.Core
命名空间,以便在调用
TimeChanged
事件后使用
Behaviors SDK
触发命令

<!-- XAML Namespaces -->
xmlns:interact="using:Microsoft.Xaml.Interactivity"
xmlns:interactcore="using:Microsoft.Xaml.Interactions.Core"

<TimePicker x:Name="TestTimePicker" ClockIdentifier="24HourClock" Time="0">
    <interact:Interaction.Behaviors>
        <interactcore:EventTriggerBehavior EventName="TimeChanged">
            <interactcore:InvokeCommandAction Command="{Binding DataContext.TimeChangedCommand}" CommandParameter="{Binding ElementName=TestTimePicker, Path=Time}" />
        </interactcore:EventTriggerBehavior>
    </interact:Interaction.Behaviors>
</TimePicker>
初始化页面后,将抛出带有以下消息的
InvalidOperationException

Adding or removing event handlers dynamically is not supported on WinRT events.

感谢您的讨论@Archana。我找到了解决问题的办法。 我现在使用编译绑定
x:Bind
直接将事件与
ViewModel
中的处理程序连接,而不是使用
Binding
ViewModel
中的
命令连接

我更新了
时间选择器
控件

<TimePicker x:Name="TestTimePicker" ClockIdentifier="24HourClock" Time="{x:Bind ViewModel.TestTime, Mode=TwoWay}" TimeChanged="{x:Bind ViewModel.TestTimeChangedEvent}" />

感谢您的讨论@Archana。我找到了解决问题的办法。 我现在使用编译绑定
x:Bind
直接将事件与
ViewModel
中的处理程序连接,而不是使用
Binding
ViewModel
中的
命令连接

我更新了
时间选择器
控件

<TimePicker x:Name="TestTimePicker" ClockIdentifier="24HourClock" Time="{x:Bind ViewModel.TestTime, Mode=TwoWay}" TimeChanged="{x:Bind ViewModel.TestTimeChangedEvent}" />
参考此

EventTriggerBehavior不支持TimeChanged事件。支持的事件包括

    Tapped
    PointerPressed  
    Loaded
    DataContextChanged
    Click
    Checked
    Unchecked
    SelectionChanged
    TextChanged
    Toggled
NavigationCompleted
您必须实现自定义行为以支持TimeChanged事件

这里有一个实现自定义行为的链接参见此

EventTriggerBehavior不支持TimeChanged事件。支持的事件包括

    Tapped
    PointerPressed  
    Loaded
    DataContextChanged
    Click
    Checked
    Unchecked
    SelectionChanged
    TextChanged
    Toggled
NavigationCompleted
您必须实现自定义行为以支持TimeChanged事件


这里有一个实现自定义行为的链接

您现在能告诉我问题出在哪里吗?对不起!问题更新是的,这来自模板10。让我们参考此链接。EventTriggerBehavior不支持TimeChanged事件您能告诉我现在出现了什么问题吗?抱歉!问题更新是的,这来自模板10。让我们参考此链接。EventTriggerBehavior不支持TimeChanged Event很奇怪,这很难实现MVVM。很奇怪,这很难实现MVVM。