Element Binding in XAML for Windows Phone Application

Element Binding in XAML can be explained as the binding of one control to the properties of second control so that on changing the value of first control causes change to the properties of the second control. This can be explained with a simple example of Slider and a TextBlock.

The XAML code for the main page is as follows:

<phone:PhoneApplicationPage

    x:Class="PhoneApp2.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">
    <StackPanel>
        <Slider Name="slider1" Minimum="10" Maximum="500" Value="100"></Slider>
        <TextBlock FontSize="{Binding Value,ElementName=slider1}">Test</TextBlock>        
    </StackPanel>  

</phone:PhoneApplicationPage>


And the designer view for this page is as under:


Element Binding in XAML for Windows Phone Application Element Binding in XAML for Windows Phone Application Reviewed by Afsar Murad on 02:01 Rating: 5
Powered by Blogger.