0

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?

4

1 回答 1

3

在 Windows Phone 的样式设置器中不可能有绑定,但也许这篇文章可以帮助你。
否则,我看到你唯一能做的就是创建一个继承 ListBox 的类,或者使用 GetContainerForItemOverride 并在代码中创建绑定。

于 2013-09-16T18:37:25.307 回答