I have a Style defined in my App.xaml file:
<Style x:Key="TileListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="12,12,0,0"/>
<Setter Property="Background" Value="{StaticResource PhoneAccentBrush}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Width" Value="210"/>
<Setter Property="Height" Value="210"/>
<!--<Setter Property="HorizontalAlignment" Value="Left"/>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid>
<Rectangle Fill="{TemplateBinding Background}"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now I need to change the Background property with a Binding within my PhoneApplicationPage XAML file:
<UserControl.Resources>
<Style x:Key="TileListBoxItemStyle2" TargetType="ListBoxItem" BasedOn="{StaticResource TileListBoxItemStyle}">
<Setter Property="Background" Value="{Binding Color}" />
</Style>
</UserControl.Resources>
The following Exception is thrown:
{System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.Setter.Value'. [Line: 23 Position: 49] ---> System.NotSupportedException: Cannot set read-only property ''.
at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
This does not work although I searched the web and it seems to work, but maybe there's a limitation of Windows Phone?