Closed RaminMT closed 7 years ago
By default, that's exactly what will be passed to the command!
Just make sure you don't set theCommandParameter
or Converter
properties and also that your command execution method can actually receive the parameter!
Oops! Thank you! I didn't know that!
No problem! Please do close this issue if this solves the problem! 😄
what if I need sender and args?
@HppZ the sender
is currently being ignored; if you need it, my advice is to copy the source code for the InvokeCommandAction
to your project and change the Execute
method to match your needs!
OK, got you, thanks.
maybe you can add this feature.
Hi @PedroLamas , my question is:
Is it possible to binding one property of xxxEventArgs with CommandParameter?
For example, I want pass Uri
of NavigationEventArgs
. Because NavigationEventArgs
belongs to View layer, we'd better not pass it to ViewModel.
<WebView local:WebViewEx.Uri="{Binding LoginUri, Mode=OneTime}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="LoadCompleted">
<Core:InvokeCommandAction Command="{Binding LoginCommand}" CommandParameter="{Binding Uri}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</WebView>
@manupstairs Binding to Source property of WebView using ElementName
Thanks @HppZ for you quickly reply. In fact I tried, it can works if I write
<Core:InvokeCommandAction Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=webView}"/>
I can find xxxWebView.Source is changed after LoadCompleted event.
But if I just write
<Core:InvokeCommandAction Command="{Binding LoginCommand}" CommandParameter="{Binding Source,ElementName=webView}"/>
The source of WebView will keep the origin value in ViewModel.
Sorry I forget to say I want to use WebView for a OAuth login. I wan to get response uri after user login.
@manupstairs you can just create and pass a custom converter that will take the event args and return the uri from it!
Should look something like this:
<WebView local:WebViewEx.Uri="{Binding LoginUri, Mode=OneTime}">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="LoadCompleted">
<Core:InvokeCommandAction Command="{Binding LoginCommand}" InputConverter="{StaticResource MyCustomConverter}"/>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</WebView>
Very Cool! Thanks Pedrolamas!
Hi, sorry to reopen this issue. @PedroLamas or @manupstairs do you have any sample code for Custom Converter? I'm building an UWP app and using WebView too
Thanks
@bromoapp all you need is a class that implements IValueConverter
:
public class MyCustomConverter : Windows.UI.Xaml.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
//implement your conversion operation here
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
//you can leave this one like this as it's not required for this case
throw new NotImplementedException();
}
}
I want to bind CommandParameter
to the a property of the control that triggered the action, for example:
<NavigationView IsSettingsVisible="True">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="ItemInvoked">
<core:EventTriggerBehavior.Actions>
<core:InvokeCommandAction Command="{Binding MenuNavigated}"
CommandParameter="{Binding <InvokeItem>.Tag}" />
</core:EventTriggerBehavior.Actions>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
<NavigationView.MenuItems>
<NavigationViewItem Icon="Contact" Content="Contacts" Tag="contacts"/>
</NavigationView.MenuItems>
</NavigationView>
How can I achieve that?
@weitzhandler please don't reply to closed issues with new/different context of the issue itself. As what you wrote is more of a question than an issue, I also recomment that you use StackOverflow, tagging the question with the UWP
tag.
Having said that, what you want should be possible by just adding a name to the control (like x:Name="ControlName"
) and then using {Binding TheControlProperty, ElementName=ControlName}
@PedroLamas tx for your reply
There is no element name, it's auto generated from data-template. I want to refer to the currently selected NavigationViewItem
.
Anyway, I switched from using a command to a SelectedItem
in my VM and finished.
Hi, Is it possible to use event arguments as parameter for commands when using InvokeCommandAction?! Actually I'm using ItemClick event with behaviors on a ListView & ItemClickEventArgs is the only way to know which item clicked. Maybe It's good to notice for a reason I can't use SelectedItem, because It's null when you set SelectionMode="None" & also that I'm developing UWP app in C#.
Thanks