Error when trying to bind the value of a setter

我只是一个虾纸丫 提交于 2019-12-24 14:28:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22518133/error-when-trying-to-bind-the-value-of-a-setter

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