How to detect Kids Corner Programmatically in Windows Phone 8?

The Kids Corner is one of the new feature that is introduced with the Windows Phone 8. If you encounter a scenario where you want to detect the mode of the current application like Default or Kids Corner and take actions accordingly, you can use the ApplicationProfile class.

How to detect Kids Corner Programmatically in Windows Phone 8?

The ApplicationProfile class exposes the property static property called “Modes” (ApplicationProfile.Modes) which returns one of the below modes

1. Default – This is the default mode in which the Windows Phone Application runs

2. Alternate – This is the mode where the Windows Phone Application runs in the Kids’ Corner mode.

The ApplicationProfile class is defined in the name space Windows.Phone.ApplicationModel. Hence, you should add the reference to the name space in the code behind.

Using Windows.Phone.ApplicationModel

Below is a sample code to demonstrate How to detect Kids Corner Programmatically in Windows Phone 8?

Code behind Page

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Navigation;

using Microsoft.Phone.Controls;

using Microsoft.Phone.Shell;

using PhoneApp1.Resources;

using Windows.Phone.ApplicationModel;

namespace PhoneApp1

{

public partial class MainPage : PhoneApplicationPage

{

// Constructor

public MainPage()

{

InitializeComponent();

}

private void Button_Click_1(object sender, RoutedEventArgs e)

{

string ApplicationMode = ApplicationProfile.Modes.ToString();

textbox1.Text = ApplicationMode;

}

}

}

XAML Page

<phone:PhoneApplicationPage

x:Class="PhoneApp1.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"

xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d"

FontFamily="{StaticResource PhoneFontFamilyNormal}"

FontSize="{StaticResource PhoneFontSizeNormal}"

Foreground="{StaticResource PhoneForegroundBrush}"

SupportedOrientations="Portrait" Orientation="Portrait"

shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->

<Grid x:Name="LayoutRoot" Background="Transparent">

<Grid.RowDefinitions>

<RowDefinition Height="Auto"/>

<RowDefinition Height="*"/>

</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

<TextBlock Text="@isenthil" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

<TextBlock Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}">

<Run FontSize="48" Text="MobileOSGeek"/>

</TextBlock>

</StackPanel>

<!--ContentPanel - place additional content here-->

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

<Button Content="Mode" HorizontalAlignment="Left" Height="105" Margin="58,84,0,0" VerticalAlignment="Top" Width="343" Click="Button_Click_1"/>

<TextBox x:Name="textbox1" HorizontalAlignment="Left" Height="80" Margin="10,231,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="436"/>

<TextBlock HorizontalAlignment="Left" Margin="27,204,0,0" TextWrapping="Wrap" Text="Current Mode" VerticalAlignment="Top"/>

</Grid>

</Grid>

</phone:PhoneApplicationPage>

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...