解决方法
您不需要UserControl,只需将自定义Button模板作为样式资源,然后您可以通过在任何Button实例上设置样式来重复使用它.
虽然没有Blend它是可行的,但我强烈建议你至少进行试用,这对于设计/视觉开发来说是一个非常好的IDE!
<Style x:Key="ButtonStyle1" targettype="Button"> <Setter Property="Foreground" Value="#FFFFFFFF"/> <Setter Property="Padding" Value="3"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderBrush" Value="#FF000000"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="Button"> <Grid> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="normal"/> <VisualState x:Name="MouSEOver"/> <VisualState x:Name="pressed"/> <VisualState x:Name="disabled"> <Storyboard> <DoubleAnimation Duration="0" To="0.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="disabledVisualElement"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="Focusstates"> <VisualState x:Name="Focused"> <Storyboard> <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/> </Storyboard> </VisualState> <VisualState x:Name="Unfocused"/> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <Border x:Name="Background" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF707070" Offset="0"/> <GradientStop Color="#FF666666" Offset="0.49"/> <GradientStop Color="#FF5e5e5e" Offset="0.51"/> <GradientStop Color="#FF535353" Offset="1"/> </LinearGradientBrush> </Border.Background> </Border> <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> <ContentPresenter.Effect> <DropShadowEffect BlurRadius="3" ShadowDepth="2" Opacity="0.5"/> </ContentPresenter.Effect> </ContentPresenter> <Rectangle x:Name="disabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0"/> <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" stroke="#FF6DBDD1" strokeThickness="1"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。