<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?
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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.