ListPicker FullScreen mode Background problem: workaround
published on: 2/3/2011 | Views: N/A | Tags: WP7Toolkit ListPicker
by WindowsPhoneGeek
Today we receive several questions about a possible bug in the Silverlight for Windows Phone Toolkit ListPicker control that caused regection of their apps.
Here is the problem in short: Currently setting the Background property of the ListPicker does not reflect the background color in the FullScreen mode. If you switch between different phone themes sometimes the ListPicker seems like transparent.
Here is the Question : How to change the background color of the ListPicker FullScreen mode?
Here is the answer:
All you need to do is just to make some changes into the ListPicker style(note that you will need the full style with the ControlTemplate and VisualStates). We will give two options.
Option1: Basically you have to change the Expanded Visual state in this way:
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Background"
Duration="0">
<!--<DiscreteObjectKeyFrame
Value="{StaticResource PhoneTextBoxEditBackgroundColor}"
KeyTime="0"/>-->
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="YellowGreen"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>Option 2: You can comment the part of the Expanded VisualState that changes the Background of the border:
<!--<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Background"
Duration="0">
<DiscreteObjectKeyFrame
Value="{StaticResource PhoneTextBoxEditBackgroundColor}"
KeyTime="0"/>
</ObjectAnimationUsingKeyFrames>-->
Here is the full source code.
<Style TargetType="toolkit:ListPicker" x:Key="customStyle">
<!--<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="{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>
</phone:PhoneApplicationPage.Resources>
Here you can download the full source code.
You can also follow us on Twitter @winphonegeek
Comments
Problem fixed.
posted by: TH on 2/3/2011 9:56:53 PM
Thank you so much for this code. It fixed my problem.
appreciate this
posted by: KB on 2/3/2011 9:57:57 PM
Thank you for answering my question. I really appreciate it. Cheers!
Me too
posted by: Terry on 2/4/2011 1:38:07 PM
Me too... Guys thanks for answering my question so quickly.
how to style fullpopupmode header
posted by: curious1 on 2/5/2011 9:26:31 AM
Hello,
Is it possible to style the header in full mode. E.g. in your previous article you had set Header="Cities". Is it possible to template it? e.g. when listpicker is in fullpopup mode, can header contain text = cities and an image? I tried several things but could not figure it out.
Can you please provide an example? Thanks
RE:how to style fullpopupmode header
posted by: winphonegeek on 2/7/2011 7:28:34 PM
If you mean the header of the FullScreenMode then this is a known issue and is added in the to do list of the Silverligth Toolkit (you can vote for a possible fix) here: FullModeHeaderTemplate for ListPicker
For now you can only style the FullModePopup element from the ControTemplate (you can get the style from this article and customize the pop up as you prefer).
If you mean the Header on the ListPicker then you can use the HeaderTemplate property like for example:
<DataTemplate x:Name="CustomHeaderTemplate ">
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<TextBlock Text="language: "/>
<TextBlock Text="{Binding Language}" Foreground="Green"/>
</StackPanel>
</DataTemplate>
<toolkit:ListPicker x:Name="listPicker" ItemTemplate="{StaticResource PickerItemTemplate}"
HeaderTemplate ="{StaticResource CustomHeaderTemplate }" />
How to give differnt colors to items
posted by: R.Avinash on 2/24/2011 12:43:46 AM
Thank you so it fixed of my problem. But My problem is: i have two items in my list picker i want white color to the selected item and black to the unselected item.
How can i do this.plz help me.
RE:give differnt colors to items
posted by: winphonegeek on 2/24/2011 4:06:06 PM
Check this post with source code available: How to customize the ListPicker selected item
Does not work at all
posted by: fuwx on 9/21/2011 12:43:15 PM
Neither Option 1 nor option 2 does work with WP SDK 7.1 RC. I get some sort of semi-transparent background instead of solid one.
Doesnt work for Aug 11
posted by: petka on 10/14/2011 1:00:07 AM
Please update this example to be workable with Aug 2011 Toolkit
Doesnt work for wp7.1
posted by: Avinash on 4/14/2012 10:36:09 AM
I have downloaded the code and also copied the code from this page but it does not work for me. Please can you give correct solution for this.
Not effective for Nokia Lumia 800
posted by: Sojanya Tripathi on 5/4/2012 10:56:34 AM
Hey Geek Team,
I have tried on 7.1 SDK for lumia 800 but can't see any reflection :(
Please look into it and provide your suggestion.
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
