WPF mvvm向导(WPF mvvm wizard)

编程入门 行业动态 更新时间:2024-10-11 09:23:08
WPF mvvm向导(WPF mvvm wizard)

我正在实现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>

                    
                     
          

更多推荐

本文发布于:2023-07-29 03:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1311945.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向导   WPF   mvvm   wizard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!