在WP7中更改ListPicker的FullMode中的背景?

时间:2011-09-28 12:26:49

标签: windows-phone-7 background-color windows-phone-7.1 listpicker

任何人都知道如何在ListPicker的FullMode中轻松更改背景?我需要设置样式才能做到这一点吗?我试过了,但找不到合适的地方来设置背景......如果是需要使用的风格,我可以在那种样式中设置背景吗?任何帮助将受到高度赞赏:)

以下是ListPicker的标准样式:

<Style TargetType="toolkit:ListPicker"> 
    <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/> 
    <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/> 
    <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
    <Setter Property="HorizontalContentAlignment" Value="Left"/> 
    <Setter Property="Margin" Value="{StaticResource PhoneTouchTargetOverhang}"/> 
    <Setter Property="Template"> 
        <Setter.Value> 
            <ControlTemplate TargetType="toolkit:ListPicker"> 
                <StackPanel> 
                    <VisualStateManager.VisualStateGroups> 
                        <VisualStateGroup x:Name="PickerStates"> 
                            <VisualState x:Name="Normal"/> 
                            <VisualState x:Name="Expanded"> 
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames 
                                        Storyboard.TargetName="Border" 
                                        Storyboard.TargetProperty="Background" 
                                        Duration="0"> 
                                        <DiscreteObjectKeyFrame 
                                            Value="{StaticResource PhoneTextBoxEditBackgroundColor}" 
                                            KeyTime="0"/> 
                                    </ObjectAnimationUsingKeyFrames> 
                                    <ObjectAnimationUsingKeyFrames 
                                        Storyboard.TargetName="Border" 
                                        Storyboard.TargetProperty="BorderBrush" 
                                        Duration="0"> 
                                        <DiscreteObjectKeyFrame 
                                            Value="{StaticResource PhoneTextBoxEditBorderBrush}" 
                                            KeyTime="0"/> 
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </VisualState> 
                        </VisualStateGroup> 
                    </VisualStateManager.VisualStateGroups> 
                    <ContentControl 
                        Content="{TemplateBinding Header}" 
                        ContentTemplate="{TemplateBinding HeaderTemplate}" 
                        Foreground="{StaticResource PhoneSubtleBrush}" 
                        FontSize="{StaticResource PhoneFontSizeNormal}" 
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                        Margin="0 0 0 8"/> 
                    <Grid> 
                        <Border 
                            x:Name="Border" 
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding Background}" 
                            BorderThickness="2"> 
                            <Canvas x:Name="ItemsPresenterHost" MinHeight="46"> 
                                <ItemsPresenter x:Name="ItemsPresenter"> 
                                    <ItemsPresenter.RenderTransform> 
                                        <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/> 
                                    </ItemsPresenter.RenderTransform> 
                                </ItemsPresenter> 
                            </Canvas> 
                        </Border> 
                        <Popup x:Name="FullModePopup"> 
                            <Border Background="{StaticResource PhoneChromeBrush}"> <!-- Popup.Child should always be a Border --> 
                                <Grid> 
                                    <Grid.RowDefinitions> 
                                        <RowDefinition Height="Auto"/> 
                                        <RowDefinition/> 
                                    </Grid.RowDefinitions> 
                                    <ContentControl 
                                        Grid.Row="0" 
                                        Content="{TemplateBinding FullModeHeader}" 
                                        Foreground="{StaticResource PhoneForegroundBrush}" 
                                        FontFamily="{StaticResource PhoneFontFamilySemiBold}" 
                                        FontSize="{StaticResource PhoneFontSizeMedium}" 
                                        HorizontalAlignment="Left" 
                                        Margin="24 12 0 0"/> 
                                    <ListBox 
                                        x:Name="FullModeSelector" 
                                        Grid.Row="1" 
                                        ItemTemplate="{TemplateBinding ActualFullModeItemTemplate}" 
                                        FontSize="{TemplateBinding FontSize}" 
                                        Margin="{StaticResource PhoneMargin}"> 
                                        <ListBox.ItemsPanel> 
                                            <ItemsPanelTemplate> 
                                                <StackPanel/> <!-- Ensures all containers will be available during the Loaded event --> 
                                            </ItemsPanelTemplate> 
                                        </ListBox.ItemsPanel> 
                                    </ListBox> 
                                </Grid> 
                            </Border> 
                        </Popup> 
                    </Grid> 
                </StackPanel> 
            </ControlTemplate> 
        </Setter.Value> 
    </Setter> 
</Style>

2 个答案:

答案 0 :(得分:1)

没有办法通过模板来做到这一点。

执行此操作的唯一方法是更改​​控件的来源。 (您需要更改Style的{​​{1}}。)

具体来说,您需要更改TargetType="controls:ListPicker"

的内容

答案 1 :(得分:1)

我想知道同样的事情。

虽然无法直接更改ListPicker的背景颜色,但它会跟随PhoneChromeBrush资源的颜色,因此您可以覆盖所有这些颜色。你的应用程序可以更改此背景的颜色。

例如:

((SolidColorBrush)App.Current.Resources["PhoneChromeBrush"]).Color = Colors.Cyan;