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
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

How To: Programmatically Detect Current Theme in Windows Phone

Karthikeyan Anbarasan user avatar by
Karthikeyan Anbarasan
·
Jun. 28, 12 · Interview
Like (0)
Save
Tweet
Share
8.60K Views

Join the DZone community and get the full member experience.

Join For Free

In this tutorial we are going to see how to programmatically detect which is the current theme that is running in a device from any application. It would be useful for application that are required to change the theme based on the selection or any requirement that requires for a theme change. PhoneDarkThemeVisibility class will be used to detect the theme to which the device is registered, and theme can be changed easily from the setting page. Let us see how exactly we can detect the theme in this article, Open Visual Studio and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below.

image

Now drag and drop few controls which are used to display the detected theme, basically a text block which shows the end result of the selected theme just for our reference as shown in the screen below.

image

Now we need to write the below code in the code behind event which basically detect the theme running the background and will provide us with an option to do some changes as per the selection as shown in the code below.

Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace F5debugHowto40
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            Visibility dbgisibility = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];

            if (dbgisibility == Visibility.Visible)
            {
                textBlock2.Text = " Dark Theme";
            }
            else
            {
                textBlock2.Text = " Light Theme";
            }
        }
    }
}

Now we are done with our code, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.

Output Screen:

image

Now change the Theme by Pressing the Windows Button in the Emulator and going to Settings, then select theme to Light as shown in the screen below. Here basically we are changing the theme so that the application will detect the theme without changing any code.

image

Now navigate back to the application to see the expected output as shown in the screen below.

image

That’s it from this tutorial, we have seen how to programmatically detect the selected theme which can be used to play around with in the application for better visibility. See you all in the next tutorial until then Happy Programming.

Windows Phone application

Published at DZone with permission of Karthikeyan Anbarasan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Demystifying the Infrastructure as Code Landscape
  • Strategies for Kubernetes Cluster Administrators: Understanding Pod Scheduling
  • Building a REST API With AWS Gateway and Python
  • Tackling the Top 5 Kubernetes Debugging Challenges

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: