Please help to create the Row Double Click event for datagrid using MVVM, currently i am using MouseDoubleClick event, using MouseDoubleClick event when we click anywhere on datagrid then that event is firing. Please help me to produce the event only when double click on rows.
Code that currently i am using i.e. MouseDoubleClick event:
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding RowClick}" CommandParameter="{Binding ElementName=grdManageCab, Path=SelectedItem}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
You are Subscribing the event on the DataGrid. And when you DoubleClick the entire Datagrid will fire the event. If you want that this event fire only on the Cells you must susbribe this evento on a DataGridCell
<DataGrid>
<DataGridCell>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding RowClick}" CommandParameter="{Binding ElementName=grdManageCab, Path=SelectedItem}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGridCell>
</DataGrid>
For more info please here.
Hope helps. Greetings!
Related
I encountered an UI issue when developing an app using MAUI flyoutItem. According to the official doc, it looks like I can only define the flyoutItem appearance by setting two columns(https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/flyout?view=net-maui-7.0): one bind to FlyoutIcon and the other bind to Title.
What if I want to add a third item such as a label for identity/status or a slide button to enable/disable? I expect sth look like this:
[column 0]FlyoutIcon [column 1]Label1 [column 2]Label2/Slide Button
Can you please also show me some sample code for the solution?
Best and Regards
I tried to modify the Grid to add a third column and addition Label but seems not working.
<Shell ...>
...
<Shell.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="0.2*,0.4*,0.4*">
<Image Source="{Binding FlyoutIcon}"
Margin="5"
HeightRequest="45" />
<Label Grid.Column="1"
Text="{Binding Title}"
FontAttributes="Italic"
VerticalTextAlignment="Center" />
<Label Grid.Column="2"
Text="{Binding Text}"
FontAttributes="Italic"
VerticalTextAlignment="End" />
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
</Shell>
Er, guys. Looks like using Menu Item instead of FlyoutItem will resolve the issue.
I am following the below discussion,
Handling Mouse Events in MVVM in WPF
It is working for one event but when I try to multiple events, it is not working.
I want to bind multiple events like below:
<i:Interaction.Triggers>
<i:EventTrigger
EventName="PreviewMouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding TripLegCopyIconPressedCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding
TripLegPreviewMouseLeftButtonUpCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
But it is not working. How to do that? Any idea?
Thanks.
As per my understanding, multiple event binding will work and not recommended.
I need to perform login. I'm binding Login to my ViewModel. I can't bind password from passwordBox so I pass it through EventToCommand parametrer
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cmd:EventToCommand Command="{Binding LogInCommand,
Mode=OneWay}"
CommandParameter="{Binding Password,
ElementName=PasswordBox,
Mode=OneWay}"
/>
</i:EventTrigger>
</i:Interaction.Triggers>
My problem - when loginbox has focus the login in ViewModel is null. How to force lost focus when the button is tap.
I know that is not exactly the answer to your question, but still..
You can find here a realization of login dialog using MVVM
http://www.geoffhudik.com/tech/2012/2/19/windows-phone-login-navigation.html
I am using recently released Windows.UI.Interactivity library to wire some events to MVVM commands in a WinRT app. It works fine for ListView, however no event is fired in a ComboBox. Here's a ComboBox control definition (some properties skipped for clarity):
<ComboBox
x:Name="collectionMode"
Margin="10"
SelectedIndex="0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CollectionModeCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBoxItem Content="Show collection properties" />
<ComboBoxItem Content="Show collection data" />
</ComboBox>
The CollectionModeCommand is never triggered (I have a similar wiring in a ListView and it works fine).
Any help is appreciated.
Resolved. The problem was with the incorrect binding of the outer control that of course resulted in the CollectionModeCommand not being bound to the ComboBox.
I have a treeview where I can click on items. I am using MVVM light toolkit and the EventToCommand and would like to know which item was chosen. How can I pass this to my viewmodel?
<interact:Interaction.Triggers>
<interact:EventTrigger EventName="SelectedItemChanged">
<cmd:EventToCommand Command="{Binding Path=DataContext.SimpleCommand, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Mode=OneWay}"
CommandParameter="{Binding SelectedItems, ElementName=mainTreeView}"
/>
</interact:EventTrigger>
</interact:Interaction.Triggers>
http://www.galasoft.ch/mvvm/#intro With the newest version, you can get the EventArgs of the fired event directly in the ViewModel to handle it.