Reputation: 11
I would like to use MouseBinding for TextBlock in my WPF application. Although I have found WPF Datagrid MouseBinding MVVM and that works.
My problem is when I do a double mouse click on TextBlock which does not contain a string it's not working (check screenshot). Is there any solution for that?
Xaml Code
<ListView ItemsSource="{Binding SomeList}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}">
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding SayHello}"/>
</TextBlock.InputBindings>
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Upvotes: 0
Views: 264
Reputation: 11389
You can achiev this by setting HorizontalContentAlignment
and / or VerticalContentAlignment
at your ListView
like
<ListView ItemsSource="{Binding SomeList}"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
See the microsoft docs for more info.
Upvotes: 0