문제

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>
도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top