0
<Grid>
<ComboBox x:Name="ColorRepresentationComboBox" Margin="0,12,0,0"  Width="120" >
<ComboBoxItem x:Name="HEXComboBoxItem" Content="HEX" PointerPressed="HEXComboBoxItem_PointerPressed"/>
<ComboBoxItem x:Name="HSLComboBoxItem" Content="HSL" PointerPressed="HSLComboBoxItem_PointerPressed"/>
</ComboBox>
   </Grid>



private void HEXComboBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
{

}

private void HSLComboBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
{

}

PointerEntered Event work properly,but pointerPressed event is not fired.I dont Know why?

2 Answers2

1

In this case, it should be that the PointerPressed event has been specially handled inside the ComboBox.

If you want to capture the click event of ComboBoxItem, you can consider using Tapped event.

<ComboBoxItem x:Name="HEXComboBoxItem" Content="HEX" Tapped="HEXComboBoxItem_Tapped"/>
private void HEXComboBoxItem_Tapped(object sender, TappedRoutedEventArgs e)
{
    Debug.WriteLine("tapped");
}

If you just want to get the selected item after the ComboBox selected item is changed, you can consider using this method:

<ComboBox SelectionChanged="ComboBox_SelectionChanged">
    <ComboBoxItem x:Name="HEXComboBoxItem" Content="HEX" Tapped="HEXComboBoxItem_Tapped"/>
</ComboBox>
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
    // do other things...
}

Thanks.

Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
0

There's an easy solution here. It says:

These events have to be handled not through XAML but thorugh AddHandler method.

SomeButton.AddHandler(PointerPressedEvent, 
    new PointerEventHandler(SomeButton_PointerPressed), true); 
E. Epstein
  • 739
  • 2
  • 11
  • 26