Sabtu, 30 November 2013

Parsing Json array objects in windowsphone c#

Introduction

HTTP-based Web services frequently use JavaScript Object Notation (JSON) messages to return data back to the client. JSON objects can easily be instantiated in JavaScript, without parsing logic, which makes it a convenient format for messages in Web applications.You may get solve this problem using JObject class or any third party,its is not a best solution to use third party.So i come up with my best option is "parsing json using DataContractJsonSerializer".How it is most important concept in wpf,so now i tried this in wp7.


Building the Sample

Before going to start parsing json.You must be add reference to both "system.runtime.serialization" and "system.servicemodel.web".And in this sample i am using http://json2csharp.com/ for simply building a C# class from JSON formated string.And its very important is to make class as similar to Json objects.Other wise we will never parse date properly.

Source File at :  Parsin JsonArray in windows phone

Description
This is time I am going to cover DataContract JSON Serialization using DataContractJsonSerializer.  DataContract JSON Serialization is mostly used by Windows Communication Foundation (WCF) services, but I will try to apply this approach to Windows Phone 7 environment.   

C#
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; 
using System.Runtime.Serialization.Json; 
using System.IO; 
using System.Text; 
using System.Runtime.Serialization; 
 
namespace Json_Parsing 

    public partial class MainPage : PhoneApplicationPage 
    { 
        // Constructor 
        public MainPage() 
        { 
            InitializeComponent(); 
 
            string jsonString = @"{ 
    'product': [ 
        { 
            'CATEGORYNAME': [ 
                'AshokLeyland'
                'HindustanMotorsLtd'
                'MahindraLtd'
                'TataMotors'
                'SwarajMazda' 
            ], 
            'CATEGORYID': [ 
                '1'
                '2'
                '3'
                '4'
                '6' 
            ], 
            'SUBCATEGORYNAME': [ 
                'MultiaxleVehicles'
                'HippoHaulage'
                'HippoTipper'
                'Cargo'
                'Pick-up' 
            ], 
            'SUBCATEGORYID': [ 
                '1'
                '2'
                '3'
                '4'
                '5' 
            ], 
            'TYPENAME': [ 
                'Haulage'
                'Tippers'
                'RigidTrucks'
                'Cabs'
                'DeliveryVan' 
            ], 
            'TYPEID': [ 
                '1'
                '2'
                '3'
                '4'
                '5' 
            ] 
        } 
    ], 
    'success'1
    'message''Thetruckdetailsgettingsuccessfully' 

"; 
            RootObject TotalList = new RootObject(); 
            RootObject childlistonly = new RootObject(); 
            Product prdt=new Product(); 
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); 
            DataContractJsonSerializer ser = new DataContractJsonSerializer(TotalList.GetType()); 
            TotalList = ser.ReadObject(ms) as RootObject; 
            string category = ""
            string typename = ""
            int i = 0
            int k = 0
            foreach (var d in TotalList.product) 
            { 
                foreach (var t in d.CATEGORYNAME) 
                { 
                    category = category + "" + t.ToString() + "\n" + "\n" + "\n"
                    i++; 
                } 
                
                foreach (var t in d.TYPENAME) 
                { 
                    typename = typename + "" + t.ToString() + "\n" + "\n" + "\n"
                    k++; 
                } 
                foreach (var t in d.SUBCATEGORYNAME) 
                { 
                   // teststring = teststring + "" + t.ToString() + "\n" + "\n" + "\n"; 
                    i++; 
                } 
            } 
            MessageBox.Show("Your CATEGORYNAMES are:\n\n" + category); 
            MessageBox.Show("Your TYPENAMES are:\n\n" + typename); 
            ms.Close(); 
            
             
        } 
    } 
    public class Product 
    { 
        public List<string> CATEGORYNAME { getset; } 
        public List<string> CATEGORYID { getset; } 
        public List<string> SUBCATEGORYNAME { getset; } 
        public List<string> SUBCATEGORYID { getset; } 
        public List<string> TYPENAME { getset; } 
        public List<string> TYPEID { getset; } 
    } 
 
    public class RootObject 
    { 
        public List<Product> product { getset; } 
        public int success { getset; } 
        public string message { getset; } 
    } 
}


Windows Phone tutorials for beginners key points



This section is included for only windows phone beginners.However this article can covers following questions.Off course these key words are more helpful for getting more best results about this topic in search engines like google/bing/yahoo.. 





1. How to parse the Json data or json string in windows phone 8




2.Json Parsing in WindowsPhone using DataContractJsonSerializer





3.Windows Phone JSON Parsing Example in c#





4. Parsing Complicated JSON object in windows phone 8 c#




Have a nice day by 

Jumat, 29 November 2013

Customizing Default RadioButton and CheckBoxes with our images in WindowsPhone C#

Generally it is not possible to set default radiobuttons and checkbox border , pressed state colors in windows phone using xaml,So we need to override the template of both radiobutton & checkboxes grid template.And so we may need to make customizable controls in some requirement with respect of our images.And it is best practice for if client want to know control pressed state with proper image background selection. And for our requirement, expression blend is best suitable tool for customizing radio button s as well as checkboxes and off course it is very flexible for generating customizable xaml of our app UI.
Note:
1)This sample is targeted on  windows phone 7.1
2)Here I am using expression blend 2012 which is comes under wp8 sdk.


Building the Sample

No need to add any other external dll's & libraries.Beacuse BLEND will comes on wp sdk by default.We need to add following images in project.
    

Source File at :  Radio&checkBoxStyles in windowsphone

Description

However expression blend is more efficient for customizing UI controls,To know more about custom style's you may visit http://www.geekchamp.com/tips/custom-styles-and-templates-in-windows-phone-intro.We need to follow some steps here
1)Deafault RadioButton and CheckBox Template is

XAML

 <Grid x:Name="DefaultPanel" Grid.Row="1" Margin="12,0,12,0"
            <Grid.RowDefinitions
                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="Auto"/> 
                <RowDefinition Height="*"/> 
            </Grid.RowDefinitions> 
 
            <TextBlock Grid.Row="0" Text="1.Default RadioButton and Checkbox" /> 
            <RadioButton Content="RadioButton" Grid.Row="1" Height="75" Margin="0,0,266,0"/> 
            <CheckBox Content="CheckBox" Grid.Row="1" Height="75" Margin="236,0,43,0"/> 
        </Grid>
 2)Embeded RadioButton and CheckBox custom style's in <phone:PhoneApplicationPage.Resources> wich is generated from blend.
XAML

<phone:PhoneApplicationPage.Resources
        <Style x:Key="PhoneButtonBase" TargetType="ButtonBase"> 
            <Setter Property="BackgroundValue="Transparent"/> 
            <Setter Property="BorderBrushValue="{StaticResource PhoneForegroundBrush}"/> 
            <Setter Property="ForegroundValue="{StaticResource PhoneForegroundBrush}"/> 
            <Setter Property="BorderThicknessValue="{StaticResource PhoneBorderThickness}"/> 
            <Setter Property="FontFamilyValue="{StaticResource PhoneFontFamilySemiBold}"/> 
            <Setter Property="FontSizeValue="{StaticResource PhoneFontSizeMediumLarge}"/> 
            <Setter Property="PaddingValue="10,3,10,5"/> 
            <Setter Property="Template"> 
                <Setter.Value
                    <ControlTemplate TargetType="ButtonBase"> 
                        <Grid Background="Transparent"> 
                            <VisualStateManager.VisualStateGroups
                                <VisualStateGroup x:Name="CommonStates"> 
                                    <VisualState x:Name="Normal"/> 
                                    <VisualState x:Name="MouseOver"/> 
                                    <VisualState x:Name="Pressed"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ForegroundStoryboard.TargetName="ContentContainer"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneBackgroundBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BackgroundStoryboard.TargetName="ButtonBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneForegroundBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrushStoryboard.TargetName="ButtonBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneForegroundBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="Disabled"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ForegroundStoryboard.TargetName="ContentContainer"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrushStoryboard.TargetName="ButtonBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BackgroundStoryboard.TargetName="ButtonBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="Transparent"/> 
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                </VisualStateGroup
                            </VisualStateManager.VisualStateGroups
                            <Border x:Name="ButtonBackgroundBorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0Margin="{StaticResource PhoneTouchTargetOverhang}"> 
                                <ContentControl x:Name="ContentContainerContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                            </Border
                        </Grid
                    </ControlTemplate
                </Setter.Value
            </Setter
        </Style> 
        <Style x:Key="PhoneRadioButtonCheckBoxBase" BasedOn="{StaticResource PhoneButtonBase}" TargetType="ToggleButton"> 
            <Setter Property="BackgroundValue="{StaticResource PhoneRadioCheckBoxBrush}"/> 
            <Setter Property="BorderBrushValue="{StaticResource PhoneRadioCheckBoxBrush}"/> 
            <Setter Property="FontSizeValue="{StaticResource PhoneFontSizeMedium}"/> 
            <Setter Property="FontFamilyValue="{StaticResource PhoneFontFamilyNormal}"/> 
            <Setter Property="HorizontalContentAlignmentValue="Left"/> 
            <Setter Property="VerticalContentAlignmentValue="Center"/> 
            <Setter Property="PaddingValue="0"/> 
        </Style> 
        <Style x:Key="RadioButtonStyle1" BasedOn="{StaticResource PhoneRadioButtonCheckBoxBase}" TargetType="RadioButton"> 
            <Setter Property="Template"> 
                <Setter.Value
                    <ControlTemplate TargetType="RadioButton"> 
                        <Grid Background="Transparent"> 
                            <VisualStateManager.VisualStateGroups
                                <VisualStateGroup x:Name="CommonStates"> 
                                    <VisualState x:Name="Normal"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill)" Storyboard.TargetName="CheckMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <LinearGradientBrush EndPoint="0.5,1StartPoint="0.5,0"> 
                                                            <GradientStop Color="BlackOffset="0"/> 
                                                            <GradientStop Color="#FF0C9FE4Offset="1"/> 
                                                        </LinearGradientBrush
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="MouseOver"/> 
                                    <VisualState x:Name="Pressed"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="EnabledCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Collapsed</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="PressedDarkCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="PressedLightCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="FillStoryboard.TargetName="CheckMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <LinearGradientBrush EndPoint="0.5,1StartPoint="0.5,0"> 
                                                            <GradientStop Color="BlackOffset="0"/> 
                                                            <GradientStop Color="#FFA0CCEAOffset="1"/> 
                                                        </LinearGradientBrush
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="Disabled"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="EnabledCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Collapsed</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="DisabledDarkCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="DisabledLightCheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="FillStoryboard.TargetName="CheckMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneRadioCheckBoxCheckDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ForegroundStoryboard.TargetName="ContentContainer"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                </VisualStateGroup
                                <VisualStateGroup x:Name="CheckStates"> 
                                    <VisualState x:Name="Checked"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="CheckMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="Unchecked"/> 
                                    <VisualState x:Name="Indeterminate"/> 
                                </VisualStateGroup
                                <VisualStateGroup x:Name="FocusStates"/> 
                                <VisualStateGroup x:Name="ValidationStates"/> 
                            </VisualStateManager.VisualStateGroups
                            <Grid Margin="{StaticResource PhoneTouchTargetLargeOverhang}"> 
                                <Grid.ColumnDefinitions
                                    <ColumnDefinition Width="32"/> 
                                    <ColumnDefinition Width="*"/> 
                                </Grid.ColumnDefinitions
                                <Ellipse x:Name="EnabledCheckBackground"  HorizontalAlignment="LeftHeight="32IsHitTestVisible="FalseVerticalAlignment="CenterWidth="32"> 
                                    <Ellipse.Fill
                                        <ImageBrush  Stretch="UniformImageSource="/Images/radio_n_hdpi.png"/> 
                                    </Ellipse.Fill
                                </Ellipse
                                <Canvas  HorizontalAlignment="LeftHeight="32IsHitTestVisible="FalseOpacity="{StaticResource PhoneDarkThemeOpacity}" VerticalAlignment="CenterWidth="32"> 
                                    <Ellipse x:Name="PressedDarkCheckBackgroundFill="{StaticResource PhoneRadioCheckBoxPressedBrush}" Height="32Visibility="CollapsedWidth="32"/> 
                                    <Ellipse x:Name="DisabledDarkCheckBackgroundFill="{StaticResource PhoneRadioCheckBoxDisabledBrush}" Height="32Visibility="CollapsedWidth="32"/> 
                                </Canvas
                                <Canvas HorizontalAlignment="LeftHeight="32IsHitTestVisible="FalseOpacity="{StaticResource PhoneLightThemeOpacity}" VerticalAlignment="CenterWidth="32"> 
                                    <Ellipse x:Name="PressedLightCheckBackgroundFill="{StaticResource PhoneRadioCheckBoxPressedBrush}" Height="32Stroke="{StaticResource PhoneForegroundBrush}" StrokeThickness="{StaticResource PhoneStrokeThickness}" Visibility="CollapsedWidth="32"/> 
                                    <Ellipse x:Name="DisabledLightCheckBackgroundFill="{StaticResource PhoneRadioCheckBoxDisabledBrush}" Height="32Stroke="{StaticResource PhoneDisabledBrush}" StrokeThickness="{StaticResource PhoneStrokeThickness}" Visibility="CollapsedWidth="32"/> 
                                </Canvas
                                <Ellipse  x:Name="CheckMark"  HorizontalAlignment="CenterHeight="16IsHitTestVisible="FalseVisibility="CollapsedVerticalAlignment="CenterWidth="16"/> 
                                <ContentControl x:Name="ContentContainerContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="12,0,0,0Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                            </Grid
                        </Grid
                    </ControlTemplate
                </Setter.Value
            </Setter
        </Style> 
 
 
        <Style x:Key="CheckBoxStyle1" BasedOn="{StaticResource PhoneRadioButtonCheckBoxBase}" TargetType="CheckBox"> 
            <Setter Property="Template"> 
                <Setter.Value
                    <ControlTemplate TargetType="CheckBox"> 
                        <Grid Background="Transparent"> 
                            <VisualStateManager.VisualStateGroups
                                <VisualStateGroup x:Name="CommonStates"> 
                                    <VisualState x:Name="Normal"/> 
                                    <VisualState x:Name="MouseOver"/> 
                                    <VisualState x:Name="Pressed"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrushStoryboard.TargetName="CheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneRadioCheckBoxPressedBorderBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="FillStoryboard.TargetName="IndeterminateMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneRadioCheckBoxCheckBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="Disabled"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrushStoryboard.TargetName="CheckBackground"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="FillStoryboard.TargetName="IndeterminateMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneRadioCheckBoxCheckDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ForegroundStoryboard.TargetName="ContentContainer"> 
                                                <DiscreteObjectKeyFrame KeyTime="0Value="{StaticResource PhoneDisabledBrush}"/> 
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                </VisualStateGroup
                                <VisualStateGroup x:Name="CheckStates"> 
                                    <VisualState x:Name="Checked"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="CheckMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                    <VisualState x:Name="Unchecked"/> 
                                    <VisualState x:Name="Indeterminate"> 
                                        <Storyboard
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="VisibilityStoryboard.TargetName="IndeterminateMark"> 
                                                <DiscreteObjectKeyFrame KeyTime="0"> 
                                                    <DiscreteObjectKeyFrame.Value
                                                        <Visibility>Visible</Visibility
                                                    </DiscreteObjectKeyFrame.Value
                                                </DiscreteObjectKeyFrame
                                            </ObjectAnimationUsingKeyFrames
                                        </Storyboard
                                    </VisualState
                                </VisualStateGroup
                            </VisualStateManager.VisualStateGroups
                            <Grid  Margin="{StaticResource PhoneTouchTargetLargeOverhang}"> 
                                <Grid.ColumnDefinitions
                                    <ColumnDefinition Width="32"/> 
                                    <ColumnDefinition Width="*"/> 
                                </Grid.ColumnDefinitions
                                <Border x:Name="CheckBackground"  
                                     BorderBrush="Gray
                                     BorderThickness="3
                                      Background="WhiteHorizontalAlignment="Left
                                       Height="32IsHitTestVisible="FalseVerticalAlignment="Center
                                     Width="32"></Border
                                <Rectangle x:Name="IndeterminateMarkFill="{StaticResource PhoneRadioCheckBoxCheckBrush}" HorizontalAlignment="CenterHeight="16IsHitTestVisible="FalseGrid.Row="0Visibility="CollapsedVerticalAlignment="CenterWidth="16"/> 
                                <Image Source="/Images/check_s_hdpi.pngx:Name="CheckMarkHorizontalAlignment="CenterHeight="32"  
                        IsHitTestVisible="FalseStretch="Fill"  Visibility="CollapsedVerticalAlignment="CenterWidth="32"/> 
                                <ContentControl x:Name="ContentContainerContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="12,0,0,0Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                            </Grid
                        </Grid
                    </ControlTemplate
                </Setter.Value
            </Setter
        </Style> 
    </phone:PhoneApplicationPage.Resources>
3)Applying styles for both radiobutton and checkbox
XAML

<RadioButton Style="{StaticResource RadioButtonStyle1}" Content="RadioButton" Grid.Row="1" Height="75" Margin="0,0,266,0"/> 
<CheckBox Style="{StaticResource CheckBoxStyle1}" Content="CheckBox" Grid.Row="1" Height="75" Margin="236,0,43,0"/>
 in C#, we can apply static resources like this way
C#

//For checkbox 
checkboxname.Style = (Style)this.Resources["CheckBoxStyle1"]; 
 
//For radiobutton 
 
radiobuttonname.Style = (Style)this.Resources["RadioButtonStyle1"];
4)ScreenShot


Windows Phone tutorials for beginners key points

This section is included for only windows phone beginners.However this article can covers following questions.Off course these key words is more helpful for getting more best results about this topic in search engines like google/bing/yahoo.. 

1.How to customizing radio buttons in windows phone 8 c#,xaml

2.How to customizing checkbox in windows phone 8 c#,xaml

3.c# windows phone 8 how to add style to a button/checkbox/radio button/textblock/TextBox..

4.How to add the style in windows phone 8 C#

5.How to set the style in windows phone 8 C#

6.How to set the style in windows phone 8 C#

7.Custom styles and templates in windows phone 8 C# xaml using expression blend



Have a nice day by