我正在实现WPF MVVM向导,我想知道在加载新的向导页面(UserControl)时执行DoOperation的正确方法。
DoOperation在MyWizard.ViewModal类上实现,而UserControl Load在MyWizard.View命名空间发生。
如何在UserControl加载的事件与DoOperation api之间建立连接?
我尝试了以下方法:
<xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/ </i:EventTrigger> </i:Interaction.Triggers>RunOperation调用DoOperation 。
它不起作用, RunOperation没有被调用。
这是正确的方法还是有更好的方法在MyWizard.ViewModal类上执行操作?
I am implementing WPF MVVM Wizard and I am wondering about the right approach of performing a DoOperation when a new Wizard’s Page (UserControl) is loaded.
The DoOperation is implemented on the MyWizard.ViewModal class while the UserControl Load is happening at the MyWizard.View namespaces.
How can I connect between the UserControl loaded event to the DoOperation api?
I tried the following:
<xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/ </i:EventTrigger> </i:Interaction.Triggers>RunOperation calls DoOperation.
it doesn’t work, RunOperation is not being called.
This is the right approach or there is a better way to perform an operation at the MyWizard.ViewModal class?
最满意答案
你的方法应该有效。 您是否检查过输出控制台是否存在绑定错误? RunOperation是一个命令吗? 当引发Loaded事件时,是否已设置UserControl的DataContext? 你在UC中实现了这样的触发器吗?
<UserControl x:Class="..." xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/> </i:EventTrigger> </i:Interaction.Triggers> <Grid> ... </Grid> </UserControl>Your approach should work. Have you checked your output console for binding errors? Is RunOperation a command? Is the DataContext of the UserControl already set, when the Loaded event is raised? Have you implemented the triggers like this in your UC?
<UserControl x:Class="..." xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"> <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <i:InvokeCommandAction Command="{Binding Path=RunOperation}"/> </i:EventTrigger> </i:Interaction.Triggers> <Grid> ... </Grid> </UserControl>
更多推荐
发布评论