1
votes

In a UWP Windows 10 application I'm working on have a command in my Viewmodel

public class ViewModel {
     public ICommand LoadedCommand{ get; set; } 
}

and I'd like to run it when my grid control gets the focus, without having to call the command in the code behind file.

<Grid GotFocus="Grid_GotFocus">
        <Grid.ColumnDefinitions>
        </Grid.ColumnDefinitions>
</Grid>

Does anyone know if its possible to assign the command to the event directly in the xaml and if it is how I might do it.

Many Thanks

1

1 Answers

1
votes

You can use either the InvokeCommandAction from the XAML Behavior library, or use x:Bind to event that's available in the Anniversary Update. So you can have something like -

GotFocus="{x:Bind Vm.OnGridGotFocus}"

Note the OnGridGotFocus() here is a method and it can either have no parameters or matdch the signiture of the event.