【发布时间】:2013-09-21 00:10:40
【问题描述】:
我的 App.xaml 文件中定义了一个样式:
<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>
现在我需要在 PhoneApplicationPage XAML 文件中使用 Binding 更改 Background 属性:
<UserControl.Resources>
<Style x:Key="TileListBoxItemStyle2" TargetType="ListBoxItem" BasedOn="{StaticResource TileListBoxItemStyle}">
<Setter Property="Background" Value="{Binding Color}" />
</Style>
</UserControl.Resources>
抛出以下异常:
{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)
这不起作用,虽然我搜索了网络,它似乎可以工作,但可能是 Windows Phone 的限制?
【问题讨论】:
标签: c# xaml binding windows-phone-8 windows-phone