How to make a ButtonSpinner's buttons not close the Popup in which it is placed?

最后都变了- 提交于 2020-02-07 05:21:51

问题


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:

  1. PreviewMouseLeftButtonDown
  2. MouseLeftButtonDown
  3. PreviewMouseDown
  4. MouseDown
  5. Click
  6. PreviewMouseUp
  7. MouseUp
  8. PreviewMouseLeftButtonUp
  9. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!