silverlight 中的自定义按钮

发布于 2024-11-10 08:55:24 字数 163 浏览 1 评论 0原文

我怎样才能在 silverlight 中创建这样的按钮。我需要表达混合吗?

由于我需要在应用程序中的许多地方使用修改后的按钮,我应该将其作为用户控件来执行吗?

在此处输入图像描述

How can I create buttons like this in silverlight. Do I need expression blend for this.

Since I need to use the modified buttons at many places in my application, should I do it as a user control?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

睫毛上残留的泪 2024-11-17 08:55:24

为此,您不需要 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>

You don't need a UserControl for this, just a custom Button template as a style resource, which then you can reuse by setting the style on any Button instance.

While it's doable without Blend, I highly recommend you at least get the trial, it's a really really nice IDE for design / visual development!

Edit: As a little present here's a starting point :)

<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>
彡翼 2024-11-17 08:55:24

您可以在不使用 Blend 的情况下手动完成此操作,但请相信我,使用 Blend 将为您提供更多功能,并且如果您决定自己完成这一切,您将在所需的时间内获得更惊人的结果。

You can do it without Blend by hand, but believe me, using Blend will give you a lot more power and you'll get more amazing results in the fraction of time you would need if you decided to do it all by yourself.

随风而去 2024-11-17 08:55:24

我绝对推荐 Blend,因为它可以在设计控件样式和创建模板时节省大量时间。

但是,如果您不希望按钮完全与图像相同,则可以使用多个主题(例如JetPack),您可以从中借用模板并在 XAML 中相对轻松地修改颜色。

I'd definitely recommend Blend as it saves so much time when styling controls and creating templates.

However, if you're not set on having the buttons exactly the same as the image, there are several themes that you could use (such as JetPack) from which you could borrow the templates and amend the colours relatively easily in XAML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文