Listpicker fullmode背景Windows Phone 8

时间:2013-11-18 12:00:49

标签: xaml windows-phone-8 windows-phone toolkit

我正在尝试在listpicker的fullmode中设置背景。 我已经看到了这个:http://www.geekchamp.com/tips/listpicker-fullscreen-mode-background-problem-workaround但它似乎不适用于Windows Phone 8 ListPicker,因为模板不同?

这是我的模板:

    <ControlTemplate x:Key="ListPickerControlTemplate" TargetType="toolkit:ListPicker">
    <StackPanel>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="PickerStates">
                <VisualState x:Name="Normal">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="Header"
                            Storyboard.TargetProperty="Foreground"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource AppDefaultBlueColor}"
                                KeyTime="0"/>
                            </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                    </VisualState>
                <VisualState x:Name="Highlighted">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="UserControl"
                            Storyboard.TargetProperty="Foreground"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource PhoneTextBoxForegroundBrush}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <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>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="Header"
                            Storyboard.TargetProperty="Foreground"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource AppDefaultBlueColor}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Disabled">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="Border"
                            Storyboard.TargetProperty="Background"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource TransparentBrush}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="Border"
                            Storyboard.TargetProperty="BorderBrush"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource PhoneDisabledBrush}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="UserControl"
                            Storyboard.TargetProperty="Foreground"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource PhoneDisabledBrush}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames
                            Storyboard.TargetName="Header"
                            Storyboard.TargetProperty="Foreground"
                            Duration="0">
                            <DiscreteObjectKeyFrame
                                Value="{StaticResource PhoneDisabledBrush}"
                                KeyTime="0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <ContentControl
        x:Name="Header"
            Content="{TemplateBinding Header}"
            ContentTemplate="{TemplateBinding HeaderTemplate}"
            Foreground="{StaticResource AppDefaultBlueColor}"
            FontSize="{StaticResource PhoneFontSizeNormal}"
            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
            Margin="0 0 0 8"/>
        <Grid >
            <Border x:Name="Border"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">
                <UserControl x:Name="UserControl" Foreground="{TemplateBinding Foreground}">
                    <StackPanel>
                        <TextBlock x:Name="MultipleSelectionModeSummary" Margin="8 8 0 8" />
                        <Canvas x:Name="ItemsPresenterHost" MinHeight="46">
                            <ItemsPresenter x:Name="ItemsPresenter">
                                <ItemsPresenter.RenderTransform>
                                    <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/>
                                </ItemsPresenter.RenderTransform>
                            </ItemsPresenter>
                        </Canvas>
                    </StackPanel>
                </UserControl>
            </Border>
        </Grid>
    </StackPanel>
</ControlTemplate>

2 个答案:

答案 0 :(得分:1)

希望这会对你有所帮助。只需在App.xaml.cs文件构造函数中添加以下行:

((SolidColorBrush)App.Current.Resources["PhoneChromeBrush"]).Color = GetColorFromHexa("#1589FF").Color;

///Conert hexa decimal color value to solidcolorBrush
SolidColorBrush GetColorFromHexa(string hexaColor) 
{
    byte r = Convert.ToByte(hexaColor.Substring(1, 2), 16);
    byte g = Convert.ToByte(hexaColor.Substring(3, 2), 16);
    byte b = Convert.ToByte(hexaColor.Substring(5, 2), 16);
    SolidColorBrush soliColorBrush = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b));
    return soliColorBrush;
}

答案 1 :(得分:0)

您可以克隆Toolkit源代码中找到的ListPickerPage.xaml,更改您喜欢的任何内容,并将ListPicker :: PickerPageUri设置为指向您自己的ListPickerPage副本。