Window_Load event in MVVM

I need to write some functions that will be executed during window_load () in WPF-MVVM. Each button will have its own command to execute. If the MVVM model has any command for the window_load () event?

+4
source share
1 answer

You will need to use interactions to execute the ie command to invoke the command on the 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.

Remember that the WindowLoaded property is a property.

public ICommand WindowLoaded { get; set; }

Later you need to create a new RelayCommand / RoutedUICommand in order to actually receive the callback.

thanks

+18
source

Source: https://habr.com/ru/post/1500308/


All Articles