问题
I have a RepeatButton inside the template of a ButtonSpinner inside a Popup. When I click it, I want the Popup to remain open but it closes. The reason for which I use this template is exactly to solve this issue.
Screenshot:
The OnMouseLeftButtonUp
event handler marks the MouseLeftButtonUp event as handled here.
I thought about using e.Handled = true
in an event handler, but I am not sure about it and that the order of events is this:
- PreviewMouseLeftButtonDown
- MouseLeftButtonDown
- PreviewMouseDown
- MouseDown
- Click
- PreviewMouseUp
- MouseUp
- PreviewMouseLeftButtonUp
- MouseLeftButtonUp
Inside the markup of the Popup, I have this:
<local:CustomIntegerUpDown Grid.Row="3" Value="1" Increment="1" ClipValueToMinMax="True" x:Name="MyCustomIntegerUpDown"/>
The following is the template I use (just for testing purposes: most of it is copy-pasted from the Extended WPF Toolkit's source code):
<xceed:ButtonSpinner.Template>
<ControlTemplate TargetType="{x:Type xceed:ButtonSpinner}">
<Border x:Name="Border"
SnapsToDevicePixels="True"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="firstContentColumn"
Width="*" />
<ColumnDefinition x:Name="secondContentColumn"
Width="Auto" />
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="contentPresenter"
Focusable="False"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Grid x:Name="gridContent"
Grid.Column="1"
Visibility="{TemplateBinding ShowButtonSpinner, Converter={StaticResource BooleanToVisibilityConverter}}"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RepeatButton x:Name="PART_IncreaseButton"
Style="{DynamicResource {x:Static themes:ResourceKeys.SpinnerButtonStyleKey}}"
IsTabStop="{TemplateBinding IsTabStop}"
ContentTemplate="{StaticResource IncreaseGlyphNormalKey}" >
</RepeatButton>
<RepeatButton x:Name="PART_DecreaseButton"
Grid.Row="1"
Style="{DynamicResource {x:Static themes:ResourceKeys.SpinnerButtonStyleKey}}"
IsTabStop="{TemplateBinding IsTabStop}"
ContentTemplate="{StaticResource DecreaseGlyphNormalKey}" >
</RepeatButton>
</Grid>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background"
Value="{DynamicResource {x:Static themes:ResourceKeys.ControlDisabledBackgroundKey}}" />
</Trigger>
<Trigger SourceName="PART_IncreaseButton"
Property="IsEnabled"
Value="False">
<Setter TargetName="PART_IncreaseButton"
Property="ContentTemplate"
Value="{StaticResource IncreaseGlyphDisabledKey}" />
</Trigger>
<Trigger SourceName="PART_DecreaseButton"
Property="IsEnabled"
Value="False">
<Setter TargetName="PART_DecreaseButton"
Property="ContentTemplate"
Value="{StaticResource DecreaseGlyphDisabledKey}" />
</Trigger>
<Trigger Property="ButtonSpinnerLocation"
Value="Left">
<Setter TargetName="firstContentColumn"
Property="Width"
Value="Auto" />
<Setter TargetName="secondContentColumn"
Property="Width"
Value="*" />
<Setter TargetName="contentPresenter"
Property="Grid.Column"
Value="1" />
<Setter TargetName="gridContent"
Property="Grid.Column"
Value="0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</xceed:ButtonSpinner.Template>
I did not find with Google the order of the mouse events, and I do not know if it is possible to solve the issue in this way.
来源:https://stackoverflow.com/questions/56441981/how-to-make-a-buttonspinners-buttons-not-close-the-popup-in-which-it-is-placed