如何将属性值链接到 Blend 4 中样式的属性?

发布于 2024-09-12 00:47:47 字数 2721 浏览 2 评论 0原文

我在 Blend 4 中为按钮创建了一个样式模板,但我不确定如何将标签的内容链接到按钮的内容属性。

这是样式 XAML:

<Style x:Key="NavButton" TargetType="Button">
    <Setter Property="Background" Value="#FF1F3B53"/>
    <Setter Property="Foreground" Value="#FF000000"/>
    <Setter Property="Padding" Value="3"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="BorderBrush">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFA3AEB9" Offset="0"/>
                <GradientStop Color="#FF8399A9" Offset="0.375"/>
                <GradientStop Color="#FF718597" Offset="0.375"/>
                <GradientStop Color="#FF617584" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Disabled"/>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver"/>
                            <VisualState x:Name="Pressed"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Rectangle Stroke="#FF0E1AD2" RadiusY="7" RadiusX="7" StrokeThickness="4">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.517,1.07" StartPoint="0.511,0.001">
                                <GradientStop Color="#FF1828AB" Offset="1"/>
                                <GradientStop Color="#FFFBDEDE"/>
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle Margin="15,6,11,15" RadiusY="7" RadiusX="7" Stroke="#FF0E11D2" StrokeThickness="0">
                        <Rectangle.Fill>
                            <SolidColorBrush Color="White" Opacity="0.3"/>
                        </Rectangle.Fill>
                    </Rectangle>
                    <sdk:Label Margin="8" RenderTransformOrigin="1.567,-0.25" HorizontalContentAlignment="Center" Content="Button"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I created a Style template in Blend 4 for a button, but I'm not sure how to link the Label's Content to the Button's Content property.

Here's the style XAML:

<Style x:Key="NavButton" TargetType="Button">
    <Setter Property="Background" Value="#FF1F3B53"/>
    <Setter Property="Foreground" Value="#FF000000"/>
    <Setter Property="Padding" Value="3"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="BorderBrush">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFA3AEB9" Offset="0"/>
                <GradientStop Color="#FF8399A9" Offset="0.375"/>
                <GradientStop Color="#FF718597" Offset="0.375"/>
                <GradientStop Color="#FF617584" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Disabled"/>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver"/>
                            <VisualState x:Name="Pressed"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Rectangle Stroke="#FF0E1AD2" RadiusY="7" RadiusX="7" StrokeThickness="4">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.517,1.07" StartPoint="0.511,0.001">
                                <GradientStop Color="#FF1828AB" Offset="1"/>
                                <GradientStop Color="#FFFBDEDE"/>
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle Margin="15,6,11,15" RadiusY="7" RadiusX="7" Stroke="#FF0E11D2" StrokeThickness="0">
                        <Rectangle.Fill>
                            <SolidColorBrush Color="White" Opacity="0.3"/>
                        </Rectangle.Fill>
                    </Rectangle>
                    <sdk:Label Margin="8" RenderTransformOrigin="1.567,-0.25" HorizontalContentAlignment="Center" Content="Button"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

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

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

发布评论

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

评论(1

天邊彩虹 2024-09-19 00:47:47

您可以使用模板绑定将控件模板内的控件绑定到它们正在模板化的控件的属性。例如:

<Label Content="{TemplateBinding Content}"/>

You use template bindings to bind controls inside a control template to properties of the control that they're templating. For example:

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