Window_Load event in MVVM

南笙酒味 提交于 2019-12-04 07:21:27
Nitin

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 namespace has EventTrigger and InvokeCommandAction.

Don't forget that the WindowLoaded is a property.

public ICommand WindowLoaded { get; set; }

You later have to create new RelayCommand/RoutedUICommand to actually receive the callback.

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!