I want to style the legend items of the WinRT XAML Toolkit Chart Control.
I checked the source code and found the following style:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:datavis="using:WinRTXamlToolkit.Controls.DataVisualization">
<Style
TargetType="datavis:Legend">
<Setter
Property="BorderBrush"
Value="Black" />
<Setter
Property="BorderThickness"
Value="1" />
<Setter
Property="IsTabStop"
Value="False" />
<Setter
Property="TitleStyle">
<Setter.Value>
<Style
TargetType="datavis:Title">
<Setter
Property="Margin"
Value="0,5,0,10" />
<Setter
Property="FontWeight"
Value="Bold" />
<Setter
Property="HorizontalAlignment"
Value="Center" />
</Style>
</Setter.Value>
</Setter>
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="datavis:Legend">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<datavis:Title
Grid.Row="0"
x:Name="HeaderContent"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Style="{TemplateBinding TitleStyle}" />
<ScrollViewer
Grid.Row="1"
VerticalScrollBarVisibility="Auto"
BorderThickness="0"
Padding="0"
IsTabStop="False">
<ItemsPresenter
x:Name="Items"
Margin="10,0,10,10" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
but this styles the Legend container and Title only.
how can I style the legend items ??
EDIT:
Thanks a lot Filip for the answer, this is exactly what I wanted.
but Visual Studio gave me an error at:
<Setter.Value>
<ItemsPanelTemplate>
<controls:UniformGrid
Columns="1"
Rows="5" />
</ItemsPanelTemplate>
</Setter.Value>
it said the controls:UniformGrid was not found, I removed this section and managed to get things working.
A thing to note first is that the Legend control is an ItemsControl, so you can style its items using ItemContainerStyle. An item template is governed by LegendItem style which you can find in the source too. The way to style it all in an application is to set the Style of the Legend by setting the LegendStyle property on the Chart control. Then in the Legend style set ItemContainerStyle to a Style of LegendItem. I haven't checked if the Chart control behaves correctly in Blend, but that would be the best place to edit these if it does. I just handcrafted this sample.
<charting:Chart
x:Name="PieChart"
Title="Pie Chart"
Margin="70,0">
<charting:Chart.Series>
<Series:PieSeries
Title="Population"
ItemsSource="{Binding Items}"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True" />
</charting:Chart.Series>
<charting:Chart.LegendStyle>
<Style
TargetType="datavis:Legend">
<Setter
Property="VerticalAlignment"
Value="Stretch" />
<Setter
Property="Background"
Value="#444" />
<Setter
Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<controls:UniformGrid
Columns="1"
Rows="5" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter
Property="TitleStyle">
<Setter.Value>
<Style
TargetType="datavis:Title">
<Setter
Property="Margin"
Value="0,5,0,10" />
<Setter
Property="FontWeight"
Value="Bold" />
<Setter
Property="HorizontalAlignment"
Value="Center" />
</Style>
</Setter.Value>
</Setter>
<Setter
Property="ItemContainerStyle"
xmlns:series="using:WinRTXamlToolkit.Controls.DataVisualization.Charting">
<Setter.Value>
<Style
TargetType="series:LegendItem">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="series:LegendItem">
<Border
MinWidth="200"
Margin="20,10"
CornerRadius="10"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{Binding Background}">
<datavis:Title
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
FontWeight="Bold"
Content="{TemplateBinding Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="datavis:Legend">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<datavis:Title
Grid.Row="0"
x:Name="HeaderContent"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Style="{TemplateBinding TitleStyle}" />
<ScrollViewer
Grid.Row="1"
VerticalScrollBarVisibility="Auto"
BorderThickness="0"
Padding="0"
IsTabStop="False">
<ItemsPresenter
x:Name="Items"
Margin="10,0,10,10" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:Chart.LegendStyle>
</charting:Chart>
Related
Hi i have one listview with datatemplate with items
Visibility="Visible" ScrollViewer.VerticalScrollMode="Auto"
Height="{Binding ElementName=stck_main,Path=ActualHeight}"
SelectionChanged="lst_OutletDetails_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="5,0,0,0" />
<!--<Setter Property="Background" Value="Green"/>
<Setter Property="Opacity" Value="0.8"/>
<Setter Property="Height" Value="80"/>-->
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="100" >
<Rectangle Fill="Orange" Width="5"/>
<Grid x:Name="grd_items_outletdetails" Background="{Binding ItemBackground}" Width="{Binding ElementName=lst_OutletDetails,Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition ></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition ></RowDefinition>
<RowDefinition ></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="{Binding OutletName}" Margin="5,0,0,0" Foreground="White" FontSize="22" Grid.Row="0" />
<TextBlock Text="{Binding LastVisitedDate}" VerticalAlignment="Center" Foreground="White" FontSize="18"
Grid.Row="0" Margin="5,0,40,0" HorizontalAlignment="Right" />
<TextBlock Text="{Binding OutletCode}" Foreground="White" Margin="5,0,0,0" FontSize="18" HorizontalAlignment="Left" Grid.Row="1"/>
<StackPanel Orientation="Horizontal" Margin="5,0,20,0" Grid.Row="1" HorizontalAlignment="Right">
<TextBlock Text="ISM:" Foreground="White" Margin="0,0,0,0" FontSize="18" />
<TextBlock Text="{Binding ISMName}" Foreground="White" Margin="5,0,20,0" FontSize="18" />
</StackPanel>
<TextBlock Text="{Binding Route}" Margin="5,0,0,0" FontSize="18" Grid.Row="2" HorizontalAlignment="Left" Foreground="White" />
<StackPanel Orientation="Horizontal" Margin="5,0,20,0" Grid.Row="2" HorizontalAlignment="Right">
<TextBlock Text="Status:" Foreground="White" Margin="5,0,0,0" FontSize="18" ></TextBlock>
<TextBlock Text="{Binding Status}" Foreground="White" Margin="5,0,20,0" FontSize="18" />
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
i want to change the colors of few items ,,, using mvvm pattern in windows phone 8.1
Put your question (problem) outside the codeblocks, it's hidden now.
What do you exactly want to do? Do you want to change the background color of few elements on your listbox? Describe it more precisely :)
As I can see you bind the ItemBackground property to your Grid Background, so just change the ItemBackground of elements you want in your source collection.
my problem is exactly similar to this article
But I need to implement in wp8.1 runtime. I want textblock (name=txt_latest_update) in view while scrolling
here is my XAML code
<Grid Name="Root_content" Background="#FFF7FDF7">
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="Red">
<Image Source="/Assets/nepaltoday.png" HorizontalAlignment="Left" Margin="10,0,0,0"/>
</Border>
<ScrollViewer Grid.Row="1" Name="frontpage_scrollview" VerticalScrollBarVisibility="Visible"
>
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="300"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Image Name="startscren" Stretch="Fill"/>
<Grid>
<Grid.Background>
<LinearGradientBrush StartPoint="0.3,0" EndPoint="1,0.">
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="Black" Offset="1.2" />
</LinearGradientBrush>
</Grid.Background>
</Grid>
<Grid HorizontalAlignment="Right" Margin="0,10,10,0">
<StackPanel>
<TextBlock Name="txt_nepali_date" Foreground="White" FontSize="26"/>
<TextBlock Name="txt_eng_date" Foreground="White" FontSize="26" />
<TextBlock Name="txt_temp" Foreground="Yellow" FontSize="44" Margin="0,20,0,0"/>
<TextBlock Name="txt_location" FontSize="22"/>
</StackPanel>
</Grid>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="0,1,1,1"/>
<Setter Property="Height" Value="Auto"/>
<Setter Property="Margin" Value="0,0,0,-20"/>
</Style>
</Grid.Resources>
<StackPanel Grid.Column="0">
<Button Name="btnNews" Click="btnNews_Click">
<Image Source="/Assets/FrontPage/horoscope.png" VerticalAlignment="Stretch"/>
</Button>
<Button Name="btnHoroscope" Click="btnHoroscope_Click">
<Image Source="/Assets/FrontPage/horoscope.png"/>
</Button>
<Button Name="btnCurrencyExchanges" Click="btnCurrencyExchanges_Click">
<Image Source="/Assets/FrontPage/currency exchange.png"/>
</Button>
<Button Name="btnStockExchanges" Click="btnStockExchange">
<Image Source="/Assets/FrontPage/on this day.png"/>
</Button>
<Button Name="btnOnthisday" Click="btnOnthisday_Click">
<Image Source="/Assets/FrontPage/horoscope.png"/>
</Button>
<Button Name="btnMovie" Click="btnMovie_Click">
<Image Source="/Assets/FrontPage/horoscope.png"/>
</Button>
</StackPanel>
<StackPanel Grid.Column="1" >
<Button Name="btnWeather" Click="btnWeather_Click">
<Image Source="/Assets/FrontPage/whether.png"/>
</Button>
<Button Name="btnLoadshedding" Click="btnLoadshedding_Click">
<Image Source="/Assets/FrontPage/loadshedding.png"/>
</Button>
<Button Name="btnGoldSilver" Click="btnGoldSilver_Click">
<Image Source="/Assets/FrontPage/gold_silver rates.png"/>
</Button>
<Button Name="btnTheatre" Click="btnTheatre_Click">
<Image Source="/Assets/FrontPage/theater.png"/>
</Button>
<Button Name="btnCalendar" Click="btnCalendars">
<Image Source="/Assets/FrontPage/horoscope.png"/>
</Button>
</StackPanel>
</Grid>
</Grid>
</StackPanel >
</ScrollViewer>
<Border Name="TitleBorder" Grid.Row="1"
Background="#FF264778" Opacity="0.7"
Margin="0,260,0,0"
Height="{Binding ElementName=TitleText, Path=Height}"
VerticalAlignment="Top">
<TextBlock Name="txt_lastest_update" HorizontalAlignment="Center"
Text="keep in view"
Foreground="White"
FontSize="22"
Margin="12" />
</Border>
</Grid>
Any suggestion?
hey i think your problem is, you want keep your textblock fixed while list is scroll. so you have to keep your list in different grid and textblock in different grid which need to fix. and make grid which contain list scrolable = true.
I have tried both with width="auto" and HorizontalAlignment="Stretch", but both of them do not give me the result I want. It seems that the width of the text box is always based on the size of the header of the text box. Why?
This is the XMAL:
<ListView Width="auto">
<TextBox Width="auto"
Header="Please Enter Email Address"/>
<TextBox HorizontalAlignment="Stretch"
Header="Please Enter Email address"/>
</ListView>
This is the output:
This is what I am looking for:
I get the above screenshot by setting the width to a fixed values. But I want to find a way to let the text box automatically resize base on the parent view (for example a ListView in this case).
Edit:
Based on Alan's answer, it works great in portrait mode. But still not taking the full width in landscape.
<ListView x:Name="lv" Width="auto">
<TextBox Width="{Binding ElementName=lv, Path=ActualWidth}"
Header="Please Enter Email Address"/>
<TextBox Width="{Binding ElementName=lv, Path=ActualWidth}"
Header="Please Enter Email address"/>
</ListView>
Left Image: portrait mode; Right Image: landscape mode.
Edit 2:
I notice that both #Alan's answer and #Jogy's answer are both okay if the parent view is <Page>. However, if the parent view is <ContentDialog>, neither of them works. As a matter of fact, if the parent view is <Page>, simple using this <TextBox Width="auto"/> will works as expected. There may be obvious thing about Windows Phone I don't understand.
Instead of binding the Width, try to add this below the opening ListView tag:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
[UPDATE]
Apparently there is a problem with ContentDialog and landscape mode.
Check this thread:
https://social.msdn.microsoft.com/Forums/en-US/6c8ad10c-3b27-4991-9a5a-8cb15b338709/contentdialog-behavior-in-landscape-orientation?forum=wpdevelop
If you set the background color of the List to Red, you will see that the whole List is cropped when the phone is in Landscape mode.
Bind the Width to its parent control's ActualWidth like below:
<ListView x:Name="lv" Width="auto">
<TextBox Width="{Binding ElementName=lv, Path=ActualWidth}"
Header="Please Enter Email Address"/>
<TextBox Width="{Binding ElementName=lv, Path=ActualWidth}"
Header="Please Enter Email address"/>
</ListView>
[Update]
Because the actualwidth property will not be updated on orientation change. Let's try a different way:
<Page.Resources>
<Style TargetType="ListViewItem" x:Key="StretchedListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</Page.Resources>
<Grid>
<ListView ItemContainerStyle="{StaticResource StretchedListViewItem}" x:Name="lv" Width="auto">
<TextBox Width="auto"
Header="Please Enter Email Address"/>
<TextBox Width="auto"
Header="Please Enter Email address"/>
</ListView>
</Grid>
[Update 2]
[Why]
This is a very interesting topic, it's about how to override the Control's default style.
Let me explain why we cannot make our previous solution for Page to work in ContentDialog. It's because the ContentDialog has the following default style in generic.xaml(you can find in the windows phone 8.1 sdk):
<!-- Default style for Windows.UI.Xaml.Controls.ContentDialog -->
<!-- NOTE: Because this type didn't ship in WinBlue, we use a prefix to trick the
XAML parser to not only consider its own type table when parsing, even though
this exists in a jupiter-owned namespace. -->
<Style TargetType="controls:ContentDialog">
<Setter Property="Background" Value="{ThemeResource ContentDialogBackgroundThemeBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:ContentDialog">
<Border x:Name="Container">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Orientation">
<VisualState x:Name="Portrait" />
<VisualState x:Name="Landscape">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="ContentPanel" EnableDependentAnimation="True">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ContentDialogContentLandscapeWidth}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="ContentPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="Left" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border x:Name="BackgroundElement"
Background="{TemplateBinding Background}"
FlowDirection="LeftToRight">
<Border FlowDirection="{TemplateBinding FlowDirection}">
<Grid x:Name="ContentPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogTitleMinHeight}" />
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogContentMinHeight}" />
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogButtonsMinHeight}" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentControl x:Name="Title"
Margin="{ThemeResource ContentDialogTitleMargin}"
Content="{TemplateBinding Title}"
ContentTemplate="{TemplateBinding TitleTemplate}"
FontSize="{StaticResource TextStyleExtraLargeFontSize}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
FontWeight="SemiBold"
Grid.ColumnSpan="2" />
<ContentPresenter x:Name="Content"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
FontSize="{StaticResource TextStyleLargeFontSize}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
Margin="{ThemeResource ContentDialogContentMargin}"
Grid.Row="1"
Grid.ColumnSpan="2" />
<Border x:Name="Button1Host" Padding="{ThemeResource ContentDialogButton1HostPadding}" Grid.Row="2" />
<Border x:Name="Button2Host" Padding="{ThemeResource ContentDialogButton2HostPadding}" Grid.Row="2" Grid.Column="1" />
</Grid>
</Border>
</Border>
</Grid >
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The interest things which cause the difference from Page:
the margins of title and content were set to(suggest to keep it):
ContentDialogTitleMargin 19,33.5,19,0
ContentDialogContentMargin 19,16.5,19,0
2: the width in Landscape mode was set to:
...
<x:Double x:Key="ContentDialogContentLandscapeWidth">400</x:Double>
...
the HorizontalAlignment in Landscape mode was set to:
Value="Left"
[Solution]
In addition to the steps I provided before(just need to change the Page.Resources to ContentDialog.Resources), we need to do the following steps
To solve the issue, add the following into your App.xaml:
<Application.Resources>
<Style x:Key="FullScreenContentDialogStyle" TargetType="ContentDialog">
<Setter Property="Background" Value="{ThemeResource ContentDialogBackgroundThemeBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentDialog">
<Border x:Name="Container">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Orientation">
<VisualState x:Name="Portrait" />
<VisualState x:Name="Landscape">
<Storyboard>
<!--<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="ContentPanel" EnableDependentAnimation="True">
<DiscreteObjectKeyFrame KeyTime="0" Value="Auto" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="ContentPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="Stretch" />
</ObjectAnimationUsingKeyFrames>-->
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border x:Name="BackgroundElement"
Background="{TemplateBinding Background}"
FlowDirection="LeftToRight">
<Border FlowDirection="{TemplateBinding FlowDirection}">
<Grid x:Name="ContentPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogTitleMinHeight}" />
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogContentMinHeight}" />
<RowDefinition Height="Auto" MinHeight="{ThemeResource ContentDialogButtonsMinHeight}" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentControl x:Name="Title"
Margin="{ThemeResource ContentDialogTitleMargin}"
Content="{TemplateBinding Title}"
ContentTemplate="{TemplateBinding TitleTemplate}"
FontSize="{StaticResource TextStyleExtraLargeFontSize}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
FontWeight="SemiBold"
Grid.ColumnSpan="2" />
<ContentPresenter x:Name="Content"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
FontSize="{StaticResource TextStyleLargeFontSize}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
Margin="{ThemeResource ContentDialogContentMargin}"
Grid.Row="1"
Grid.ColumnSpan="2" />
<Border x:Name="Button1Host" Padding="{ThemeResource ContentDialogButton1HostPadding}" Grid.Row="2" />
<Border x:Name="Button2Host" Padding="{ThemeResource ContentDialogButton2HostPadding}" Grid.Row="2" Grid.Column="1" />
</Grid>
</Border>
</Border>
</Grid >
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And here is the CustomContentDialog.xaml:
<ContentDialog
x:Class="CSharpWP81.CustomContentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CSharpWP81"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="DIALOG TITLE"
PrimaryButtonText="sign in"
SecondaryButtonText="cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Style="{StaticResource FullScreenContentDialogStyle}">
<ContentDialog.Resources>
<Style TargetType="ListViewItem" x:Key="StretchedListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ContentDialog.Resources>
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ListView ItemContainerStyle="{StaticResource StretchedListViewItem}" x:Name="lv">
<TextBox Width="auto"
Header="Please Enter Email Address"/>
<TextBox Width="auto"
Header="Please Enter Email address"/>
</ListView>
</StackPanel>
</ContentDialog>
I am trying to customize the hub or panorama style in WP8. Can I make Screen 1 by customizing the default hub or panorama style? I am having trouble in changing the default Screen 2 style. Is it possible, and how?
i would just create a custom header
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ItemHeaderCustomStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="44"/>
<Setter Property="Margin" Value="-12,24,30,0"/>
<Setter Property="CharacterSpacing" Value="-35"/>
<Setter Property="Foreground" Value="#EEEEEE"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Pivot>
<phone:PivotItem>
<phone:PivotItem.Header>
<TextBlock Text="main" Style="{StaticResource ItemHeaderCustomStyle}"/>
</phone:PivotItem.Header>
<StackPanel/>
</phone:PivotItem>
<phone:PivotItem>
<phone:PivotItem.Header>
<TextBlock Text="view" Style="{StaticResource ItemHeaderCustomStyle}"/>
</phone:PivotItem.Header>
<StackPanel/>
</phone:PivotItem>
<phone:PivotItem >
<phone:PivotItem.Header>
<TextBlock Text="features" Style="{StaticResource ItemHeaderCustomStyle}"/>
</phone:PivotItem.Header>
<StackPanel/>
</phone:PivotItem>
</phone:Pivot>
</Grid>
I am trying to implement a solution whereby the currently selected PivotItem Header Background is the PhoneAccentBrush, but all of the other pivot headers are a default color such as PhoneDisabledBrush. This way when the user swipes left or right, a PivotItem will come into view and its background color will change to the active PhoneAccentBrush, and all other pivot headers will remain with the default background color. How might I be able to do this?
Currently I have implemented what I want, except for the selected/nonselected pivot item backgrounds
<phone:PhoneApplicationPage.Resources>
<Style x:Key="PivotStyle1" TargetType="phone:Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<!--<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>-->
<Setter Property="Foreground" Value="white"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:Pivot">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Background="{StaticResource PhoneAccentBrush}" CacheMode="BitmapCache" Grid.RowSpan="2" />
<Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" />
<ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7"/>
<Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
<ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
...
<!--Pivot Control-->
<phone:Pivot x:Name="Pivot" Style="{StaticResource PivotStyle1}">
...
</phone:Pivot>
Which looks like..
*Update
StackTrace Exception in the following update.. InvalidOperationException: Cannot resolve TargetProperty (Border.Background).(SolidColorBrush.Color) on specified object.
<Style x:Key="PivotHeaderItemStyle1" TargetType="Primitives:PivotHeaderItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="21,0,1,0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Primitives:PivotHeaderItem">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="DarkGrey"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Red"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="myback">
<ContentControl x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Opacity="{StaticResource PhonePivotUnselectedItemOpacity}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PivotStyle1" TargetType="phone:Pivot">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<Grid/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:Pivot">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Background="{TemplateBinding Background}" Grid.RowSpan="3"/>
<ContentControl x:Name="TitleElement" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" HorizontalAlignment="Left" Margin="24,17,0,-7" Style="{StaticResource PivotTitleStyle}"/>
<Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1" ItemContainerStyle="{StaticResource PivotHeaderItemStyle1}"/>
<ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
K, seems you're getting there. The actions need to avoid code behind....
We're just going to add another storyboard animation for the background. And the simplest way I know how to do this is just add a border.
Add a Border around your < ContentControl x:Name="contentPresenter" /> so it looks like this
<Border x:Name="myback" Background="{TemplateBinding Background}">
<ContentControl x:Name="contentPresenter"/>
</Border>
Now lets color it based on the Selected State. Add in your other Storyboard animations as well.
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="DarkGrey"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Red"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Let me know it goes well :D