user10523325
user10523325

Reputation: 11

WPF C# MouseBinding for TextBlock for the whole length of block

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>

screenshot

Upvotes: 0

Views: 264

Answers (1)

Fruchtzwerg
Fruchtzwerg

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

Related Questions