Silverlight 4.0是否支持样式设置器中的绑定? [英] Does Silverlight 4.0 support bindings in a style setter?

查看:66
本文介绍了Silverlight 4.0是否支持样式设置器中的绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将应用程序从WPF移植到Silverlight,但由于某些非常简单的绑定而失败。

I am trying to port an application from WPF to Silverlight but it fails on some very simple binding.

我有以下简单示例:

    <ListBox >
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
               <Setter Property="Canvas.Top" Value="{Binding X}"></Setter>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas></Canvas>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
       </ListBox>

但是,Silverlight解析崩溃。
但是,如果我用常量替换绑定,则可以:

However, Silverlight parsing crashes. However, if I replace the binding with a constant, things are OK:

    <ListBox >
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
               <Setter Property="Canvas.Top" Value="3"></Setter>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas></Canvas>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        </ListBox>

这是为什么?

推荐答案

您可以尝试以下解决方法:

You can try this workaround:

http://blogs.msdn .com / delay / archive / 2009/11/02 / as-the-platform-evolves-so-do-theworkarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx

这篇关于Silverlight 4.0是否支持样式设置器中的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆