I need to bind the double click event of a textblock (or potentially an image as well - either way, its a user control), to a command in my ViewModel.
TextBlock.InputBindings does not seem to bind correctly to my commands, any help?
I need to bind the double click event of a textblock (or potentially an image as well - either way, its a user control), to a command in my ViewModel.
TextBlock.InputBindings does not seem to bind correctly to my commands, any help?
I also had a similar issue where I needed to bind the MouseDoubleClick event of a listview to a command in my ViewModel.
The simplest solution I came up is putting a dummy button which has the desired command binding and calling the Execute method of the button's command in the eventhandler of the MouseDoubleClick event.
.xaml
<Button Visibility="Collapsed" Name="doubleClickButton" Command="{Binding Path=CommandShowCompanyCards}"></Button>
<ListView MouseDoubleClick="ListView_MouseDoubleClick" SelectedItem="{Binding Path=SelectedCompany, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" Margin="0,10,0,0" ItemsSource="{Binding Path=CompanyList, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" HorizontalContentAlignment="Stretch" >
codebehind
private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
doubleClickButton.Command.Execute(null);
}
It is not straightforward but it is really simple and it works.