默认值ControlTemplate [英] Default values ControlTemplate
问题描述
您好,
在WPF中,控件的名称应该比其图形表示更多地描述其行为.但是在示例中,< Button/>已经具有图形表示,因此必须有一个默认的ControlTemplate.
是否有一个规范文档,其中列出了所有默认值(背景,前景等)?
谢谢您
<您还可以从Microsoft Expression中看到它.将控件放在此处,然后右键单击控件并编辑模板.这是我从Windows Visa的Expression Blend中获得的按钮的默认控件模板.
< Window.Resources>
< Style x:Key =" ButtonFocusVisual">
< Setter Property ="Control.Template">
< Setter.Value>
< ControlTemplate>
<矩形笔划=黑色"; StrokeDashArray ="1 2". StrokeThickness ="1".保证金="2". SnapsToDevicePixels ="true"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</样式>
< LinearGradientBrush x:Key =" ButtonNormalBackground" EndPoint ="0,1". StartPoint ="0,0&"
< GradientStop Color =#F3F3F3"偏移="0"/.
< GradientStop Color =#EBEBEB";偏移="0.5"/.
< GradientStop Color =#DDDDDD"偏移="0.5"/.
< GradientStop Color =#CDCDCD";偏移="1"/"0".
</LinearGradientBrush>
< SolidColorBrush x:Key =" ButtonNormalBorder"颜色=#FF707070"/>
< Style x:Key =" ButtonStyle1" TargetType ="{x:类型按钮}"
< Setter Property ="FocusVisualStyle";值="{{StaticResource ButtonFocusVisual}"//
< Setter Property ="Background"值="{{StaticResource ButtonNormalBackground}"//
< Setter Property ="BorderBrush"值="{{StaticResource ButtonNormalBorder}"//
< Setter Property ="BorderThickness"值="1"/> 0.
< Setter Property =前景";值="{DynamicResource {x:静态SystemColors.ControlTextBrushKey}}"//
< Setter Property ="HorizontalContentAlignment";值=中心"/"0".
< Setter Property ="VerticalContentAlignment";值=中心"/"0".
< Setter Property =填充";值="1"/> 0.
< Setter Property =模板">
< Setter.Value>
< ControlTemplate TargetType =< {x:Type Button}">
< Microsoft_Windows_Themes:ButtonChrome x:Name =" Chrome" SnapsToDevicePixels ="true"; Background ="{TemplateBinding Background}" BorderBrush ="{TemplateBinding BorderBrush}" RenderDefaulted =" {TemplateBinding IsDefaulted}" RenderMouseOver =" {TemplateBinding IsMouseOver}" RenderPressed =" {{TemplateBinding IsPressed}"
< ContentPresenter HorizontalAlignment =" {TemplateBinding HorizontalContentAlignment}"保证金="{TemplateBinding Padding}" VerticalAlignment ="{TemplateBinding VerticalContentAlignment}"; SnapsToDevicePixels ="{TemplateBinding SnapsToDevicePixels}"识别AccessKey ="True"/>.
</Microsoft_Windows_Themes:ButtonChrome>
< ControlTemplate.Triggers>
< Trigger Property ="IsKeyboardFocused";值=真".
< Setter Property ="RenderDefaulted"; TargetName ="Chrome"值=真"/"0".
</Trigger>
< Trigger Property ="ToggleButton.IsChecked";值=真".
< Setter Property ="RenderPressed" TargetName ="Chrome"值=真"/"0".
</Trigger>
< Trigger Property ="IsEnabled";值=假".
< Setter Property =前景";值=#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</样式>
</Window.Resources>
致谢
Zeeshan Amjad
Hello,
in WPF the name of a control should describe its behaivior more than its graphical representation. But in example a <Button/> already has a graphical representation so there must be a default ControlTemplate.
Is there a specification document where all default values are listed (Background, Foreground, ...)?
Thank You
You can also see it from Microsoft Expression. Place a control there and then right click on control and edit the template. Here is default control template for button i got it from Expression Blend on Windows Visa.
<Window.Resources> <Style x:Key="ButtonFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="2" SnapsToDevicePixels="true"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#F3F3F3" Offset="0"/> <GradientStop Color="#EBEBEB" Offset="0.5"/> <GradientStop Color="#DDDDDD" Offset="0.5"/> <GradientStop Color="#CDCDCD" Offset="1"/> </LinearGradientBrush> <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/> <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/> <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/> <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Padding" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/> </Microsoft_Windows_Themes:ButtonChrome> <ControlTemplate.Triggers> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/> </Trigger> <Trigger Property="ToggleButton.IsChecked" Value="true"> <Setter Property="RenderPressed" TargetName="Chrome" Value="true"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="#ADADAD"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources>
Regards
Zeeshan Amjad
这篇关于默认值ControlTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!