damirarh / damirscorner-utterances

utteranc.es comments for https://damirscorner.com
0 stars 0 forks source link

/blog/posts/20150221-InvokingCommandsFromEventsInWinrt.html #27

Open damirarh opened 1 year ago

damirarh commented 1 year ago

Imported

URL: https://www.damirscorner.com/blog/posts/20150221-InvokingCommandsFromEventsInWinrt.html

damirarh commented 1 year ago

Imported comment written by Yury Yatskov on 2016-05-13T22:04:45

How do I get an incoming argument when EventName = "Loaded"?

damirarh commented 1 year ago

Imported comment written by Damir Arh on 2016-05-14T09:04:19

The event argument will automatically be sent to your command if its signature allows incoming arguments. E.g.:


public ICommand ActivateCommand { get; } =
new RelayCommand<routedeventargs>(arg =>
{
// args value will be the same as
// the second argument value in the event handler
}
damirarh commented 1 year ago

Imported comment written by Yury Yatskov on 2016-05-16T15:23:06

Thank you!

Input has argument = null.

Required to pass the selected value (class) from one page to another. The value is selected in the ListView on Page1 and is passed as the input parameter Page2.

On Page1 navigation:

AppShell.Current.AppFrame.Navigate (typeof (CashAccountPageElement), SelectedCashAccount);

On Page2:
XAML:
...
xmlns: interactivity = "using: Microsoft.Xaml.Interactivity"
xmlns: core = "using: Microsoft.Xaml.Interactions.Core"
....
<interactivity: interaction.behaviors="">
<core: eventtriggerbehavior="" eventname="Loaded">
<core: invokecommandaction="" command="{Binding Path = LoadedCommand, Mode = OneWay}"/>

</interactivity:interaction.behaviors>

....

CS (ViewModel):

private RelayCommand <routedeventargs> loadedCmd;
public RelayCommand <routedeventargs> LoadedCommand
{
get
{
return this.loadedCmd ?? (This.loadedCmd = new RelayCommand <routedeventargs>

((Rea) =>

{

var result = rea;

}));

}

}

It accepts the argument "rea" of null. (SelectedCashAccount not null)
What do I need to add?

damirarh commented 1 year ago

Imported comment written by Damir Arh on 2016-05-17T21:58:20

Well, the parameter that you are passing to Page2 via Navigate method is not included in RoutedEventArgs of Loaded event.

You will need to read the value by overriding OnNavigatedTo in Page2:


protected override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter;
}

You can pass this value to the view model directly from within this method by setting a property or invoking one of its methods.

damirarh commented 1 year ago

Imported comment written by Yury Yatskov on 2016-05-17T22:03:07

Override OnNavigatedTo - works!
Thank you!