Gra*_*ult 3 wpf xaml styling .net-3.5
我在Windows 8上使用.Net 3.5,使用默认的Aero主题.
这应该是Scale Checkbox的答案,没有扩展内容,但它没有像我预期的那样容易.我试着:
我有一个UserControl与此资源:
<UserControl.Resources>
<ResourceDictionary>
<!-- ... -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/CheckBoxStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
Resources/CheckBoxStyle.xaml是这样的:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
<Style TargetType="{x:Type CheckBox}">
<Style.Resources>
<Style TargetType="{x:Type BulletDecorator}">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="2" ScaleY="2"/>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
该primitives命名空间是什么我看中需要知道BulletDecorator是什么情况.
根据这个答案,我在这里的"默认WPF主题"链接后面的.Net 3.5的Aero主题中找到了BulletDecorator.
我看到我的复选框大小没有区别.我不认为我从主题中抓取了错误的元素类型,但还有什么可能发生?
编辑1:
BulletDecorator无论如何都包含复选框的内容,所以我尝试删除了#3的要求.现在我有一个巨大的盒子和巨大的文字,并希望缩小文本.这是CheckBoxStyle.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
<Style TargetType="{x:Type CheckBox}">
<Style.Resources>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<ContentPresenter>
<ContentPresenter.LayoutTransform>
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="2" ScaleY="2"/>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
我找到了一个解决方案,虽然它并不完美.仍然可以接受更好的答案.
我使用Snoop来确定我关注的元素已经是ContentPresenter.它包含一个TextBlock,但由于某些原因无法设置样式(并且它显示在Snoop层次结构的括号中).这是我生成的CheckBoxStyle.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
<Style TargetType="{x:Type CheckBox}">
<Style.Resources>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="2" ScaleY="2"/>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5828 次 |
| 最近记录: |