DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Changing the Background for Panorama Title and Panorama Header

Toni Petrina user avatar by
Toni Petrina
·
Apr. 23, 12 · Interview
Like (0)
Save
Tweet
Share
7.82K Views

Join the DZone community and get the full member experience.

Join For Free

Control styling is an important feature in XAML and all controls that come with any framework based on it are subject to styling. Panorama is no exception to this and although it can be styled, it is not immediately obvious how to do it. For example, if we want to add background color to the panorama title and the panorama item header (similar to the Facebook app for WP7), changing the background for either control will not do the trick.

Then there are Panorama.TitleTemplate or PanoramaItem.HeaderTemplate and you can change them with the following code:

<Style TargetType="controls:Panorama">
    <Setter Property="TitleTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border Background="AliceBlue">
                    <TextBlock Text="{Binding}" />
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style TargetType="controls:PanoramaItem">
    <Setter Property="HeaderTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border Background="AliceBlue">
                    <TextBlock Text="{Binding}" />
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

But the result is not satisfying:

The aforementioned templates are quite limited in what you can do with them. To achieve the desired background color style, you need to edit the default control template. However, although you can’t get it in Visual Studio 2010, Expression Blend has that capability.

To extract the default control template, we will open the project in Expresion Blend via the inbuilt action inside Visual Studio. Right click on the project node in Solution Explorer and click the Open in Expression Blend menu option. In the Objects and Timeline panel, find the Panorama node. In the context menu for the node, select the Edit Template->Edit a Copy menu option. Simply click the OK button to use the default settings. Do the same for PanoramaItem, save changes and close Blend if you are more comfortable working in Visual Studio like me.

Your MainPage.xaml will reload with the new changes and you will have two control templates defined in the page’s resources: PanoramaControlTemplate1 and PanoramaItemControlTemplate1. Simply add the following style to set the control template for all PanoramaItems:

<Style TargetType="controls:PanoramaItem">
    <Setter Property="Template" Value="{StaticResource PanoramaItemControlTemplate1}" />
</Style>

To set the background for the title layer, add a rectangle between the PanningBackgroundLayer and PanningTitleLayer:

</controlsPrimitives:PanningBackgroundLayer>
<Rectangle Fill="LightBlue" Grid.Row="0" />
<controlsPrimitives:PanningTitleLayer ...

To set the background for the panorama item’s header layer, add a rectangle before the ContentControl:

<Rectangle Grid.Row="0" Fill="LightBlue" />
<ContentControl x:Name="header"

The results are not immediately satisfying:



You need to remove the Margin for the outermost Grid element in the PanoramaItem control template. However, you need to adjust it for ContentControl and ContentPresenter. Increase the left margin from 10 to 22 for ContentControl and wrap the ContentPresenter inside a Grid with Margin=12,0,0,0". The final result is:

Now you can go and style the panorama for your application. The same procedure can be used for styling the Pivot control, although some details may vary. Since this code is a bit hackish and you do not want to hard code your background color, you might consider creating a new control with a dependency property for setting the background color.

Go and design your unique panorama-styled applications.

 

Panorama (typesetting software)

Published at DZone with permission of Toni Petrina, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Choosing the Right Framework for Your Project
  • Best CI/CD Tools for DevOps: A Review of the Top 10
  • Microservices 101: Transactional Outbox and Inbox
  • Introduction to Spring Cloud Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: