【发布时间】:2016-07-25 01:31:09
【问题描述】:
我在 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>
对于我的ViewModel 中的代码,我使用来自Template10 的ViewModelBase 和DelegateCommand。
public DelegateCommand<TimeSpan> StartTimeChangedCommand { get; set; }
public TestViewModel()
{
...
TimeChangedCommand = new DelegateCommand<TimeSpan>(TimeChangedAction);
...
}
private void TimeChangedAction(TimeSpan obj)
{
//do something with obj
}
一旦页面被初始化,就会抛出带有以下消息的InvalidOperationException。
Adding or removing event handlers dynamically is not supported on WinRT events.
【问题讨论】:
-
你能说出现在是什么问题吗?
-
对不起!问题已更新
-
是的,这个来自Template10
-
参考此链接stackoverflow.com/questions/28474634/…。 EventTriggerBehavior 不支持 TimeChanged 事件
标签: c# xaml mvvm win-universal-app template10