【问题标题】:How to change background color of Windows Phone Listpicker in FullScreen Mode如何在全屏模式下更改 Windows Phone Listpicker 的背景颜色
【发布时间】:2012-05-09 16:31:04
【问题描述】:

以前有人问过这个问题,但提供的答案对我自己和其他人都不起作用。 listpicker 的样式是由我无法让 Listpicker 的背景改变颜色(在本例中为黄色)提供的,尽管我尝试了我能想到的每个属性来改变它。代码有什么问题?


<Style TargetType="toolkit:ListPicker" x:Key="ListPickerStyle1">
    <!--<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>-->
    <!--<Setter Property="Background" Value="YellowGreen"/>-->
    <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="Yellow" KeyTime="0"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames   Storyboard.TargetName="Border" Storyboard.TargetProperty="BorderThickness"  Duration="0">
                                        <DiscreteObjectKeyFrame  Value="200" 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="Yellow" BorderBrush="{TemplateBinding Background}"  BorderThickness="2">-->
                        <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}">-->
                            <Border Background="Yellow" BorderThickness="200">
                                <!-- Popup.Child should always be a Border -->
                                <Grid Background="Yellow">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <ContentControl   Grid.Row="0" Content="{TemplateBinding FullModeHeader}" Background="Yellow" 
                                                          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}" Background="Yellow">
                                        <ListBox.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Background="Yellow"/>
                                                <!-- Ensures all containers will be available during the Loaded event -->
                                            </ItemsPanelTemplate>
                                        </ListBox.ItemsPanel>
                                    </ListBox>
                                </Grid>
                            </Border>
                        </Popup>
                    </Grid>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

【问题讨论】:

  • 你解决了这个问题吗?

标签: xaml windows-phone-7 background popup listpicker


【解决方案1】:

我通过创建一个表示ListPickerPage 的接口并更改工具包中的任何代码引用以改用该接口(IListPickerPage) 来做到这一点。

然后,我刚刚创建了一个新的PhoneApplicationPage,并复制并稍微修改了源代码(xaml &amp; xaml.cs),(我让它实现了IListPickerPage

using System.Collections;
using System.Windows;
using System.Windows.Controls;

namespace Microsoft.Phone.Controls
{
    public interface IListPickerPage
    {
        string HeaderText { get; set; }
        IList Items { get; }
        SelectionMode SelectionMode { get; set; }
        object SelectedItem { get; set; }
        IList SelectedItems { get; }
        DataTemplate FullModeItemTemplate { get; set; }
        bool IsOpen { get; set; }
    }
}

然后,当你想使用它时,你只需指定你自己的页面,通过设置PickerPageUri

<toolkit:ListPicker x:Name="lpStr"
                    Grid.RowSpan="2"
                                    Width="1"
                                    Height="1"
                                    CacheMode="BitmapCache"
                                    ExpansionMode="FullScreenOnly"
                                    Foreground="Black"
                                    FullModeItemTemplate="{StaticResource ListPickerStringLargeTemplate}"
                                    IsHitTestVisible="False"
                                    Opacity="0"
                                    PickerPageUri="/Views/Globals/ToolkitPages/MyListPickerPage.xaml" />
            </Grid>

剩下的就是自定义您自己的ListPickerPage xaml 文件以满足您的要求。

【讨论】:

  • 这将如何改变弹出窗口的背景颜色?我只看到对前景的引用?
  • 您必须从工具包的源代码中获取 XAML 文件,并根据需要对其进行修改。然后你使用 PickerPageUri 来引用它。我故意没有把它放在这里,因为它将来会过时
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多