Does Silverlight 4.0 support bindings in a style setter?

我的梦境 提交于 2019-12-24 10:07:47

问题


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

I have the following simple example:

    <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>

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>

Why is this?


回答1:


You can try this workaround:

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




回答2:


Nop it doesn't provide that (still)



来源:https://stackoverflow.com/questions/3088644/does-silverlight-4-0-support-bindings-in-a-style-setter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!