-
it is possible to trigger a method using UI component events directly in viewModel with sender parameter ? example like button command it will directly call viewModel method same like for all UI component events. in flipView : SelectionChanged |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Did you dont get the command to work? |
Beta Was this translation helpful? Give feedback.
-
Hello @RSReswin, apologies for the delay in responding! This can be achieved with the XamlBehaviors library (NuGet packages Uno.Microsoft.Xaml.Behaviors.Interactivity.WinUI and Uno.Microsoft.Xaml.Behaviors.WinUI.Managed). For example, if you want to capture a public ICommand TextBlockDoubleTapped { get; } <Page
...
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core">
<TextBlock x:Name="textBlock" Text="Double-tap me">
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="DoubleTapped">
<interactions:InvokeCommandAction
Command="{Binding TextBlockDoubleTapped}"
CommandParameter="{Binding Text, ElementName=textBlock}"/>
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</TextBlock>
</Page> When the You can also see an example usage in one of the Uno.Samples projects here: https://github.com/unoplatform/Uno.Samples/blob/56eb46bc6c5e629888fa51a557ccdc00e52b7636/UI/UnoContoso/UnoContoso.Shared/Views/OrderDetailView.xaml#L390-L397 |
Beta Was this translation helpful? Give feedback.
Hello @RSReswin, apologies for the delay in responding!
This can be achieved with the XamlBehaviors library (NuGet packages Uno.Microsoft.Xaml.Behaviors.Interactivity.WinUI and Uno.Microsoft.Xaml.Behaviors.WinUI.Managed).
For example, if you want to capture a
TextBlock
being double-tapped, you can add an ICommand to your ViewModel to be invoked on that event: