Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top