由于我需要在我的应用程序的许多地方使用修改过的按钮,我应该作为用户控件吗?
解决方法 您不需要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>总结
以上是内存溢出为你收集整理的silverlight中的自定义按钮全部内容,希望文章能够帮你解决silverlight中的自定义按钮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)