绑定到 ControlTemplate 中的附加属性 - Silverlight

发布于 2024-08-10 08:08:02 字数 1187 浏览 11 评论 0原文

我有这种风格:

 <Style x:Key="ButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                                        <StackPanel>
                           <Image Source="{Binding Path=local:AttachedProperties.Image}"  Stretch="None" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Top"/>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

问题是绑定不适用于按钮:

<Button HorizontalAlignment="Center" Style="{StaticResource ButtonStyle}" VerticalAlignment="Center" Content="Button" local:AttachedProperties.Image="../Images/UserChart.png" Grid.RowSpan="2"/>

我做错了什么?

I have this style:

 <Style x:Key="ButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                                        <StackPanel>
                           <Image Source="{Binding Path=local:AttachedProperties.Image}"  Stretch="None" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Top"/>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </StackPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

The problem is that the binding does not work for a button:

<Button HorizontalAlignment="Center" Style="{StaticResource ButtonStyle}" VerticalAlignment="Center" Content="Button" local:AttachedProperties.Image="../Images/UserChart.png" Grid.RowSpan="2"/>

What I'm doing wrong?

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

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

发布评论

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

评论(1

旧人 2024-08-17 08:08:02

听起来,这是一个 Silverlight 问题。更多信息请参见这篇文章:

http://forums.silverlight.net/forums/ p/102737/299184.aspx

By the sounds of it, this is a Silverlight issue. More information at this post:

http://forums.silverlight.net/forums/p/102737/299184.aspx

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