• WPF小记 -- 使用Path自己画图标,点击命中(焦点)丢失问题


    在Template中,Path外面的Grid需添加Background属性值。否则点击范围会受限制,例如:Click,在RadioButton的Height和With范围内点击,命中率<1。

     <Style TargetType="{x:Type RadioButton}">
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <!--  Grid加上Background属性,点击命中不会丢失  -->
                        <Grid
                            x:Name="templateRoot"
                            Margin="5"
                            Background="Transparent"
                            SnapsToDevicePixels="True">
                            <Path
                                Name="path"
                                Width="20"
                                Height="20"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Data="M100.9,100.307 L181.5,100.307 181.5,180.60001 100.9,180.60001 z M0.5,100.307 L81.099999,100.307 81.099999,180.60001 0.5,180.60001 z M100.9,0.5 L181.5,0.5 181.5,80.793 100.9,80.793 z M0.50000539,0.5 L81.100006,0.5 81.100006,80.793 0.50000539,80.793 z"
                                Fill="#AAAAAA"
                                Stretch="Fill" />
                            <ContentPresenter
                                x:Name="contentPresenter"
                                Margin="{TemplateBinding Padding}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Focusable="False"
                                RecognizesAccessKey="True"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter TargetName="path" Property="Fill" Value="#5A84F3" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
  • 相关阅读:
    Lc5413_重新排列句子中的单词
    Lc5412._在既定时间做作业的学生人数
    Lc520_检测大写字母
    threadPoolExecutor的参数和拒绝策略
    coutdownlatch的使用
    volatile的个人理解
    Lc292_Nim 游戏
    Lc136_只出现一次的数字
    lc88_合并两个有序数组
    jdk源码_String(1)
  • 原文地址:https://www.cnblogs.com/kuangxiangnice/p/8422018.html
Copyright © 2020-2023  润新知