C# Windows Phone-使用绑定扩展现有样式
我在App.xaml文件中定义了一个样式:C# Windows Phone-使用绑定扩展现有样式,c#,xaml,binding,windows-phone-8,windows-phone,C#,Xaml,Binding,Windows Phone 8,Windows Phone,我在App.xaml文件中定义了一个样式: <Style x:Key="TileListBoxItemStyle" TargetType="ListBoxItem"> <Setter Property="Padding" Value="0"/> <Setter Property="Margin" Value="12,12,0,0"/> <Setter Property="Background" Va
<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>
这不起作用,虽然我在网上搜索了一下,它似乎起作用了,但可能Windows Phone有限制?在Windows Phone的样式设置器中不可能有绑定,但这可能会对您有所帮助。
否则,我看到您唯一能做的就是创建一个继承ListBox的类,或者veride GetContainerForItemOverride并在代码中创建绑定。在windows phone的样式设置器中不可能有绑定,但这可能对您有所帮助。
否则,我看到您可以做的唯一一件事就是创建一个继承ListBox的类,或者veride GetContainerForItemOverride并在代码中创建绑定
<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)