I have the following XAML:
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<local:DropDownButton
HorizontalAlignment="Right"
Grid.Column="2"
Width="18"
Style="{StaticResource OrangeButton}"
ContextMenuClosing="colorPallete_ContextMenuClosing"
x:Name="btnSelectColor">
<Polygon Points="0,0,5,4,10,0" Fill="Black"/>
<local:DropDownButton.DropDown>
<ContextMenu StaysOpen="True" Name="colorPallete" ContextMenuClosing="colorPallete_ContextMenuClosing">
<MenuItem StaysOpenOnClick="True" OverridesDefaultStyle="True" ContextMenuClosing="colorPallete_ContextMenuClosing">
<MenuItem.Header>
<local:ColorPickerPopup x:Name="colorPicker" ContextMenuClosing="colorPallete_ContextMenuClosing"/>
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</local:DropDownButton.DropDown>
</local:DropDownButton>
<Rectangle Width="17.5" Stroke="Black" Margin="0"
Fill="{DynamicResource CheckerBrush}"/>
<Rectangle Width="17.5" Margin="0" Name="rtcColorPreview" />
<TextBox Margin="2,0,0,0" Grid.Column="1"
Width="100" BorderThickness="0"
Text="{Binding ElementName=colorPicker, Mode=TwoWay, Path=SelectedColorName}"/>
</Grid>
The event handler colorPallete_ContextMenuClosing is not being called when ContextMenu labelled colrPallete is closing. I cannot seem to figure out what is missing.
Please help! TIA.
Per the MSDN documentation…
You would need to adjust your code so that the handler is defined solely on the
DropDownButtonas you have done. If there is a nestedContextMenuthen the nestedContextMenuwill obviously raise the event.Using a
Buttonit would look like this…..where when the
ContextMenucontaining theMenuItemcloses; the event will be raised and the handler will be called.Not certain what
DropDownButtoncontrol you are using so I can’t comment on what theDropDownproperty is and how you are nesting yourContextMenu.