MVVM中的Window_Load事件 [英] Window_Load event in MVVM
问题描述
我需要编写一些要在WPF-MVVM的window_load()期间执行的函数.每个按钮将具有自己的要执行的命令. MVVM模型中有什么命令可用于window_load()事件?
I need to write some functions to be executed during the window_load() in WPF-MVVM. Every button will have their own command to be executed. Whereas is there any command available for window_load() event in MVVM Model ?
推荐答案
您将必须使用交互来执行此操作,即在事件上调用命令.
You will have to use interactions to do that i.e to invoke command on event.
<Window
xmlns:intr="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
>
<intr:Interaction.Triggers>
<intr:EventTrigger EventName="Loaded">
<intr:InvokeCommandAction Command="{Binding WindowLoaded}"/>
</intr:EventTrigger>
</intr:Interaction.Triggers>
<!-- the rest of your XAML here -->
</Window>
Window.Interactivity命名空间具有EventTrigger和InvokeCommandAction.
Window.Interactivity namespace has EventTrigger and InvokeCommandAction.
别忘了WindowLoaded
是一个属性.
public ICommand WindowLoaded { get; set; }
您稍后必须创建新的RelayCommand/RoutedUICommand才能实际接收回调.
You later have to create new RelayCommand/RoutedUICommand to actually receive the callback.
谢谢
这篇关于MVVM中的Window_Load事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!