如何在 Expression Blend 4 中从一个模板制作具有不同背景的多个按钮

发布于 2024-10-02 07:17:22 字数 3306 浏览 2 评论 0原文

我使用“Make into control../Button”命令从矩形制作了一个简单的按钮模板。现在,我需要该模板中的多个按钮,但每个按钮必须具有不同的背景图像。我尝试在 Blend4 中执行此操作,但是当我更改按钮背景时,按钮保留模板背景(或没有,以模板中设置的为准),忽略我为该特定按钮设置的图像。 按钮模板:

btnMenu (No brush)
    -rectangle (No brush)
    -[ContentPresenter] (some text)

我很感激任何建议。

风格:

<Style x:Key="btnStyleMenuHome" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid x:Name="btnMenu" Width="90" Height="70" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Grid.Background>
                                <ImageBrush Stretch="None"/>
                            </Grid.Background>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(TileBrush.Stretch)" Storyboard.TargetName="rectangle">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Stretch>Uniform</Stretch>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="rectangle" RadiusY="5" RadiusX="5" StrokeThickness="0" Width="90" Height="70" VerticalAlignment="Center" HorizontalAlignment="Center">
                                <Rectangle.Fill>
                                    <ImageBrush Stretch="None" ImageSource="images/someImage.png"/>
                                </Rectangle.Fill>
                            </Rectangle>
                            <ContentPresenter VerticalAlignment="Bottom" Margin="7,0" d:LayoutOverrides="Width" Height="25" HorizontalAlignment="Center"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background">
                <Setter.Value>
                    <ImageBrush Stretch="None"/>
                </Setter.Value>
            </Setter>
        </Style>

I made a simple button template from the rectangle with "Make into control../Button" command. Now, I need several buttons from that template but each button must have different background image. I tried to do that in Blend4 but when I change the button background, button holds to a template background (or none, whichever is set in template), ignoring the image I have set for that specific button.
Button Template:

btnMenu (No brush)
    -rectangle (No brush)
    -[ContentPresenter] (some text)

I apreciate any advice.

Style:

<Style x:Key="btnStyleMenuHome" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid x:Name="btnMenu" Width="90" Height="70" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center">
                            <Grid.Background>
                                <ImageBrush Stretch="None"/>
                            </Grid.Background>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(TileBrush.Stretch)" Storyboard.TargetName="rectangle">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Stretch>Uniform</Stretch>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="rectangle" RadiusY="5" RadiusX="5" StrokeThickness="0" Width="90" Height="70" VerticalAlignment="Center" HorizontalAlignment="Center">
                                <Rectangle.Fill>
                                    <ImageBrush Stretch="None" ImageSource="images/someImage.png"/>
                                </Rectangle.Fill>
                            </Rectangle>
                            <ContentPresenter VerticalAlignment="Bottom" Margin="7,0" d:LayoutOverrides="Width" Height="25" HorizontalAlignment="Center"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background">
                <Setter.Value>
                    <ImageBrush Stretch="None"/>
                </Setter.Value>
            </Setter>
        </Style>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文