如果我在 WPF 中创建一个 CheckBox 控件(没有内容 - 我只需要选中/取消选中部分),它会放置“框”视觉对象(其中有或没有复选标记的 3D 矩形) )位于控件的左上角。
我可以将“盒子”视觉效果放在center而是使用 CheckBox 控件?也就是说,水平和垂直居中?像这样的事情:
通过将复选框的 HorizontalAlignment 和 VerticalAlignment 设置为 Center,我可以获得与此类似的视觉效果。这会导致 CheckBox 控件缩小到其“框”视觉效果的大小,然后在其父控件中居中。然而,它只响应“框”视觉上的点击,这呈现了一个更小且更不方便的目标。
您可以更改复选框的模板。最简单的方法是使用类似的方法复制默认模板风格窥探者 http://blog.wpfwonderland.com/2007/01/02/wpf-tools-stylesnooper/然后根据您的需要将其编辑为如下所示:
<ControlTemplate>
<BulletDecorator Background="Transparent">
<aero:BulletChrome Width="13" Height="13" Background="{TemplateBinding Panel.Background}"
BorderBrush="{TemplateBinding Border.BorderBrush}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}"
RenderPressed="{TemplateBinding ButtonBase.IsPressed}" IsChecked="{TemplateBinding ToggleButton.IsChecked}" />
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="ContentControl.HasContent" Value="True">
<Setter Property="FrameworkElement.FocusVisualStyle">
<Setter.Value>
<Style TargetType="{x:Type IFrameworkInputElement}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
StrokeThickness="1" StrokeDashArray="1 2" Margin="14,0,0,0" SnapsToDevicePixels="True" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Control.Padding" Value="4,0,0,0" />
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)