Xaml 如何设置ListPicker项目的选定颜色

Xaml 如何设置ListPicker项目的选定颜色,xaml,windows-phone-7,windows-phone-7.1,listpicker,Xaml,Windows Phone 7,Windows Phone 7.1,Listpicker,当前,ListPicker中的选定项被设置为手机强调色,如何使用自定义颜色覆盖该选项 我知道这将是一种风格,但我不确定这应该是什么…这取决于ListPicker.ExpansionMode。如果它是ExpansionAllowed,您的风格应该是这样的: <Style TargetType="toolkit:ListPickerItem"> <Setter Property="Background" Value="Transparent"/> <Se

当前,ListPicker中的选定项被设置为手机强调色,如何使用自定义颜色覆盖该选项


我知道这将是一种风格,但我不确定这应该是什么…

这取决于
ListPicker.ExpansionMode
。如果它是ExpansionAllowed,您的风格应该是这样的:

<Style TargetType="toolkit:ListPickerItem">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="Padding" Value="8 6"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="toolkit:ListPickerItem">
                <Grid x:Name="grid" Background="{TemplateBinding Background}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Unselected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="ContentContainer"
                                        Storyboard.TargetProperty="Foreground"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame  KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <!-- Normal color -->
                                                <SolidColorBrush Color="Black"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="ContentContainer"
                                        Storyboard.TargetProperty="Foreground"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <!-- Selected color -->
                                                <SolidColorBrush Color="Orange"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <!-- Optionally - background selected color -->
                                    <!--<ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="grid"
                                        Storyboard.TargetProperty="Background"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <SolidColorBrush Color="Gray"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>-->
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentControl
                        x:Name="ContentContainer"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        Foreground="{TemplateBinding Foreground}"
                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Margin="{TemplateBinding Padding}" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


但是,如果它是
FullScreenOnly
,唯一的方法是修改工具包源代码并使用所需的更改构建它。在我看来,这是不值得的。

这取决于
ListPicker.ExpansionMode
。如果它是ExpansionAllowed,您的风格应该是这样的:

<Style TargetType="toolkit:ListPickerItem">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="Padding" Value="8 6"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="toolkit:ListPickerItem">
                <Grid x:Name="grid" Background="{TemplateBinding Background}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Unselected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="ContentContainer"
                                        Storyboard.TargetProperty="Foreground"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame  KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <!-- Normal color -->
                                                <SolidColorBrush Color="Black"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="ContentContainer"
                                        Storyboard.TargetProperty="Foreground"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <!-- Selected color -->
                                                <SolidColorBrush Color="Orange"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <!-- Optionally - background selected color -->
                                    <!--<ObjectAnimationUsingKeyFrames
                                        Storyboard.TargetName="grid"
                                        Storyboard.TargetProperty="Background"
                                        Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <SolidColorBrush Color="Gray"/>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>-->
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <ContentControl
                        x:Name="ContentContainer"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        Foreground="{TemplateBinding Foreground}"
                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Margin="{TemplateBinding Padding}" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


但是,如果它是
FullScreenOnly
,唯一的方法是修改工具包源代码并使用所需的更改构建它。在我看来,这不值得。

谢谢,但我如何将其设置为ListPicker的style属性如果您想将其应用于页面上的所有
ListPicker
元素,请将其放在页面资源中,如下所示:
%YOUR_style%
我在完全干净的页面上试用过,一切正常。我在某个地方读到,我不记得确切的位置,工具包版本中存在一些模板差异,特别是
Padding
。首先,尝试10而不是6。如果这没有帮助-你有最新的工具包吗?还有一个原因可能是自定义的
ItemTemplate
,如果您有,请尝试不使用它。感谢您的帮助,但是由于依赖第三方,我不得不使用2月11日版本的toolkit,我也了解了填充问题,看起来我将放弃尝试更改它,如果这对您的设计的完整性很重要,您可以随时通过所有必要的更改来重建2月11日的工具包。在这种情况下,硬代码就可以了。谢谢,但我如何将其设置为ListPicker的style属性如果您想将其应用于页面上的所有
ListPicker
元素,请将其放在页面资源中,如下所示:
%YOUR_style%
我在完全干净的页面上试用过,一切正常。我在某个地方读到,我不记得确切的位置,工具包版本中存在一些模板差异,特别是
Padding
。首先,尝试10而不是6。如果这没有帮助-你有最新的工具包吗?还有一个原因可能是自定义的
ItemTemplate
,如果您有,请尝试不使用它。感谢您的帮助,但是由于依赖第三方,我不得不使用2月11日版本的toolkit,我也了解了填充问题,看起来我将放弃尝试更改它,如果这对您的设计的完整性很重要,您可以随时通过所有必要的更改来重建2月11日的工具包。在这种情况下,硬代码就可以了。