微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

wpf – 更改复选框的大小及其中的复选标记

我的应用程序将在具有触摸风格的计算机上运行,​​由驾驶员在驾驶时操作.我将所有的图形元素都做得更大,这样它们就可以被像我自己和更大的香肠手指一样的人操作.

我有一个需要出现在屏幕上的CheckBox.我需要缩放复选框的大小和复选标记.我尝试通过右键单击并选择Edit Tempate |来编辑Expression Blend中CheckBox的模板编辑副本.我设置了副本,因此它适用于所有复选框.

通过模板绑定它的高度和高度,我能够使盒子更大. width属性到控件的ActualHeight.但是,复选标记没有因此而增长,位于左上角.至少可以说它看起来不对.

当我编辑模板时,这是我回来的Xaml:

<Style targettype="{x:Type CheckBox}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background" Value="{StaticResource CheckBoxFillnormal}"/>
    <Setter Property="BorderBrush" Value="{StaticResource CheckBoxstroke}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource EmptyCheckBoxFocusVisual}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent" SnapsToDevicePixels="true">
                    <BulletDecorator.Bullet>
                        <Microsoft_Windows_Themes:BulletChrome BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{TemplateBinding IsChecked}" RenderMouSEOver="{TemplateBinding IsMouSEOver}" Renderpressed="{TemplateBinding Ispressed}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="{TemplateBinding ActualHeight}" Height="{TemplateBinding ActualHeight}"/>
                    </BulletDecorator.Bullet>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </BulletDecorator>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasContent" Value="true">
                        <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                        <Setter Property="Padding" Value="4,0"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Expression Blend不会让我生效BulletChrome的模板. “编辑当前”和“编辑副本”选项已禁用.

我如何完成我想做的事情?

托尼

解决方法

可以在 here on MSDN找到认的一个组成BulletDecorator示例的XAML.该页面上几乎整个XAML块都处理BulletDecorator的外观和行为.

XAML的核心是两个Path对象.第一个用于复选标记,第二个用于不确定标记(虽然名称’InderminateMark’在示例XAML中拼写错误.幸运的是,在CheckBox示例中,它的拼写始终是错误的,所以没关系.

<Path Visibility="Collapsed"
                  Width="7"
                  Height="7"
                  x:Name="checkmark"
                  SnapsToDevicePixels="False"
                  strokeThickness="2"
                  Data="M 0 0 L 7 7 M 0 7 L 7 0">
              <Path.stroke>
                <SolidColorBrush Color="{DynamicResource GlyphColor}" />
              </Path.stroke>
            </Path>
            <Path Visibility="Collapsed"
                  Width="7"
                  Height="7"
                  x:Name="InderminateMark"
                  SnapsToDevicePixels="False"
                  strokeThickness="2"
                  Data="M 0 7 L 7 0">
              <Path.stroke>
                <SolidColorBrush Color="{DynamicResource GlyphColor}" />
              </Path.stroke>
            </Path>

正如H.B.所指出的那样.在评论中,可以找到认的WPF主题here.

原文地址:https://www.jb51.cc/html/242622.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐