Question

I have a function triggered by a mouseUp event. Everything works fine, except that sometimes the mouseUp event is not detected. In fact I have a listview, with items, and when I select an item it triggers a function. But not always.

<ListView Margin="4" Grid.Row="1" Grid.ColumnSpan="2" x:Name="statinfoListview" 
  ItemsSource="{Binding Path=ExistingStateInfos, ElementName=Window}"
  SelectedItem="{Binding Path=SelectedStateInfo, ElementName=Window}">
    <ListView.ItemTemplate>
        <DataTemplate DataType="{x:Type States:StateInfo}">
            <TextBlock Text="{Binding Path=Name}" MouseUp="ApplyStateInfoNameToState_Click" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Was it helpful?

Solution

Perhaps you pull the mouse out of the textblock before you release the button? Also note you might not be clicking the textblock if you are to the right of the text, it might help to add HorizontalContentAlignment="Stretch" to the ListView.

OTHER TIPS

You have no guarentee that your MouseUp handler will be called as the event can be handled by a descendant visual in the VisualTree. You should use the tunneling event (PreviewMouseUp) if you want to be sure to catch the event.

Another alternative is to use the AddHandler method in the code behind and specifiy that you want to manage handled events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top