我试图对复选框的默认模板做一些小的调整。现在我明白了如何从头开始做一个新的模板,但是这个我不知道。我确实设法做到了(我想?)通过方法这里提取默认模板。
它喷了出来:
<ControlTemplate TargetType="CheckBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">
<BulletDecorator Background="#00FFFFFF" SnapsToDevicePixels="True">
<BulletDecorator.Bullet>
<mwt:BulletChrome Background="{TemplateBinding Panel.Background}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
BorderThickness="{TemplateBinding Border.BorderThickness}"
RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}"
RenderPressed="{TemplateBinding ButtonBase.IsPressed}"
IsChecked="{TemplateBinding ToggleButton.IsChecked}" />
</BulletDecorator.Bullet>
<ContentPresenter RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="ContentControl.HasContent">
<Setter Property="FrameworkElement.FocusVisualStyle">
<Setter.Value>
<Style TargetType="IFrameworkInputElement">
<Style.Resources>
<ResourceDictionary />
</Style.Resources>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Stroke="#FF000000"
StrokeThickness="1"
StrokeDashArray="1 2"
Margin="14,0,0,0"
SnapsToDevicePixels="True" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Control.Padding">
<Setter.Value>
<Thickness>2,0,0,0</Thickness>
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>True</s:Boolean>
</Trigger.Value>
</Trigger>
<Trigger Property="UIElement.IsEnabled">
<Setter Property="TextElement.Foreground">
<Setter.Value>
<DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>好吧,当然,我想看起来挺好的。我没有足够的经验去知道这看起来是不是对的。现在,我有两个错误:
没有找到程序集'PresentationFramework.Luna‘。验证您是否缺少程序集引用。此外,请验证您的项目和所有引用的程序集是否已经生成。
和
没有找到'mwt:BulletChrome‘型。确认您没有丢失程序集引用,并且所有引用的程序集都已生成。
现在,我想知道,如何解决这些错误,这样我才能真正开始处理模板呢?有什么更好的方法来解决这个问题吗?我的老板想要一个红色方格而不是绿色的三状态复选框,他不会接受否定的答案。
发布于 2010-05-25 19:05:24
要解决这两个错误,请添加对PresentationFramework.Luna的引用(它在GAC中,因此在选择add时,您将在.NET选项卡中找到它)。
但是,请注意,只有在默认情况下,只有在windows XP主题为露娜(默认主题)时,才会使用露娜主题。如果在显示设置中更改主题,则复选框将保留露娜主题,因为您正在重用露娜模板。
如果该模板从一开始就没有这样的设计,那么就没有其他方法只编辑现有模板的一部分了。
发布于 2010-05-25 19:05:56
修改现有模板部分的唯一方法是完全覆盖(它的副本)。您可以轻松地这样做(它将立即编译--无需手动引用任何内容)与表达式混合(编辑模板->编辑一个副本)。
在ControlTemplates中,有一件事你必须记住:
每个已知的ControlTemplate操作系统主题(露娜,Aero等)都有一个单独的。因此,在每个OS主题下,控件看起来都是正确的。如果您覆盖它,则不再是这种情况了,并且在每个操作系统下的每个主题下,它看起来都是一样的。在你的情况下,它总是看起来像Windows露娜(因为你选择露娜ControlTemplate作为起点),即使你在Vista、Win7或战舰灰色主题上运行应用程序。
因此在某种程度上,覆盖ControlTemplates在设计上是有缺陷的。当然,您可以自己为每个已知的OS主题设置一个ControlTemplate,但如果有新的主题出现,这将于事无补。
发布于 2010-05-25 19:18:58
Windows中没有包含所有控件模板的完整副本吗?
https://stackoverflow.com/questions/2907635
复制相似问题