按钮无法正确对焦于Path内部

时间:2014-07-13 12:48:41

标签: c# wpf xaml wpf-controls

我正在开发没有默认边框的Window样式,目前我正在尝试开发自定义窗口按钮,放置在右上角,就像关闭按钮一样。

问题是当一个Path作为Button的内容时,当鼠标位于Path里面时焦点无法正确呈现。

这里有一个截图来解释这个问题(我添加了一个带有绘画的“光标”,因为Windows会自动删除它) enter image description here

这是按钮定义

 <Button     Grid.Row="0"
             Grid.Column="1">
             <Path Data="F1M54.0573,47.8776L38.1771,31.9974 54.0547,16.1198C55.7604,14.4141 55.7604,11.6511 54.0573,9.94531 52.3516,8.23962 49.5859,8.23962 47.8802,9.94531L32.0026,25.8229 16.1224,9.94531C14.4167,8.23962 11.6511,8.23962 9.94794,9.94531 8.24219,11.6511 8.24219,14.4141 9.94794,16.1198L25.8255,32 9.94794,47.8776C8.24219,49.5834 8.24219,52.3477 9.94794,54.0534 11.6511,55.7572 14.4167,55.7585 16.1224,54.0534L32.0026,38.1745 47.8802,54.0534C49.5859,55.7585 52.3516,55.7572 54.0573,54.0534 55.7604,52.3477 55.763,49.5834 54.0573,47.8776z"
                Stretch="Uniform"
                Fill="#FFAAAAAA" IsHitTestVisible="False" Focusable="False" 
                Width="10"
                Margin="0" />
   </Button>

这是完整的风格

<Style x:Key="WindowDefaultStyle" TargetType="{x:Type base:BaseWindow}">
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome  GlassFrameThickness="-1" />
            </Setter.Value>
        </Setter>
        <Setter Property="AllowsTransparency" Value="True" />
        <Setter Property="Effect">
            <Setter.Value>
                <DropShadowEffect ShadowDepth="0" BlurRadius="5" Color="{DynamicResource ApplicationBorderColor}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Background" Value="{DynamicResource ApplicationBackgroundBrush}" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="WindowState" Value="Maximized" />
        <Setter Property="WindowStyle" Value="None" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type base:BaseWindow}">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock      Grid.Column="0"
                                                    Margin="4,0,0,4"
                                                    VerticalAlignment="Center"
                                                    Foreground="#FFAAAAAA"
                                                    TextWrapping="NoWrap"
                                                    Text="{TemplateBinding Title}"
                                                    FontSize="16" />

                            <Button     Grid.Row="0"
                                        Grid.Column="1">

                                <Path Data="F1M54.0573,47.8776L38.1771,31.9974 54.0547,16.1198C55.7604,14.4141 55.7604,11.6511 54.0573,9.94531 52.3516,8.23962 49.5859,8.23962 47.8802,9.94531L32.0026,25.8229 16.1224,9.94531C14.4167,8.23962 11.6511,8.23962 9.94794,9.94531 8.24219,11.6511 8.24219,14.4141 9.94794,16.1198L25.8255,32 9.94794,47.8776C8.24219,49.5834 8.24219,52.3477 9.94794,54.0534 11.6511,55.7572 14.4167,55.7585 16.1224,54.0534L32.0026,38.1745 47.8802,54.0534C49.5859,55.7585 52.3516,55.7572 54.0573,54.0534 55.7604,52.3477 55.763,49.5834 54.0573,47.8776z"
                                                    Stretch="Uniform"
                                                    Fill="#FFAAAAAA" IsHitTestVisible="False" Focusable="False" 
                                                    Width="10"
                                                    Margin="0" />

                            </Button>


                            <ContentPresenter   Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"
                                                ContentTemplate="{TemplateBinding ContentTemplate}" 
                                                Content="{TemplateBinding Content}" 
                                                ContentStringFormat="{TemplateBinding ContentStringFormat}" />
                        </Grid>

                    </Border>
               </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

此行为的任何解决方法?

0 个答案:

没有答案