试图setter的值绑定时出错 [英] Error when trying to bind the value of a setter

查看:159
本文介绍了试图setter的值绑定时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XAML:

 < ListBox.ItemsPanel>
                    < ItemsPanelTemplate>
                        <网格和GT;
                            < Grid.RowDefinitions>
                                ...
                            < /Grid.RowDefinitions>
                            < Grid.ColumnDefinitions>
                                ...
                            < /Grid.ColumnDefinitions>
                        < /网格和GT;
                    < / ItemsPanelTemplate>
                < /ListBox.ItemsPanel>
                ...
                < ListBox.ItemContainerStyle>
                    <风格的TargetType =ListBoxItem的>
                        < setter属性=Grid.RowVALUE ={结合行,模式=单向}/>
                        < setter属性=Grid.ColumnVALUE ={绑定列,模式=单向}/>
                    < /样式和GT;
                < /ListBox.ItemContainerStyle>
                ...

在页面加载后,我得到了如下的 XamlParseException


  

无法分配到财产System.Windows.Setter.Value。 [行:69职位:63]


  
  

    

的InnerException:结果
    NotSupportedException异常:无法设置只读属性


  

在错误的行号对应 Grid.Row 制定者;如果我把一个硬codeD值,而不是具有约束力的,它工作正常(但显然这不是我想要的)。

这是怎么回事?内部异常消息是没有意义的;我没有设置任何只读属性,我当然不会设置属性没有名字!

我是新来的Windows Phone,但我pretty一致的肯定code会很好地工作在WPF ......在二传手是绑定不支持WP?


解决方案

您的怀疑似乎是正确的 - 根据<一个href=\"http://blogs.msdn.com/b/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx?Redirected=true\"相对=nofollow>这篇文章,WP不支持在二传手的值绑定。

也有文章中给出解决办法,<一个href=\"http://blogs.msdn.com/b/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx?Redirected=true\"相对=nofollow>同时也出现了一个更新和<一个href=\"http://blogs.msdn.com/b/delay/archive/2010/11/10/the-taming-of-the-phone-new-settervaluebindinghelper-sample-demonstrates-its-usefulness-on-windows-phone-7-and-silverlight-4.aspx\"相对=nofollow>另一篇文章。说实话 - 我还没有与这些例子出场,但也许他们会帮助你以某种方式

I have the following XAML:

                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                ...
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                ...
                            </Grid.ColumnDefinitions>
                        </Grid>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                ...
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Grid.Row" Value="{Binding Row, Mode=OneWay}" />
                        <Setter Property="Grid.Column" Value="{Binding Column, Mode=OneWay}" />
                    </Style>
                </ListBox.ItemContainerStyle>
                ...

When the page loads, I'm getting the following XamlParseException:

Failed to assign to property 'System.Windows.Setter.Value'. [Line: 69 Position: 63]

InnerException:
NotSupportedException: Cannot set read-only property ''.

The line number in the error corresponds to the Grid.Row setter; if I put a hard-coded value instead of a binding, it works fine (but obviously it's not what I want).

What's going on? The inner exception message makes no sense; I'm not setting any read-only property, and I'm certainly not setting a property with no name!

I'm new to Windows Phone, but I'm pretty sure the same code would work fine in WPF... Is binding in a setter not supported on WP?

解决方案

Your suspicions seem to be right - according to this article, WP doesn't support Binding in the Value of a Setter.

There is also a workaround given in the article, there has also been an update and another article. To be honest - I haven't played with those examples, but maybe they will help you somehow.

这篇关于试图setter的值绑定时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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