2

任何人都知道如何轻松更改ListPicker的FullMode中的背景?我是否需要设置一种风格才能做到这一点?我已经尝试过了,但是找不到设置背景的正确位置......如果它是需要使用的样式,那么我可以在哪种样式中设置背景?任何帮助,将不胜感激:)更改WP7中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> 

回答

1

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

要做到这一点的唯一方法是通过更改控件的来源。 (您需要将Style更改为TargetType="controls:ListPicker"。)

具体来说,您需要更改FullModePopup的内容。

+1

是的,我知道我需要改变风格,但其中的风格?我试图在任何地方设置背景,但我似乎无法找到背景应该放在什么位置。我可以在第一篇文章中发布这种风格,也许您可​​以指出我可以在哪里更改背景? – kgrevehagen

1

我在想这件事。

虽然没有直接改变ListPicker的背景颜色的方式,但它与PhoneChromeBrush资源的颜色跟着一起,从而可以覆盖所有在您的应用程序的颜色来改变颜色这个背景。

例如:

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