Data Binding In Windows 8. Part 3–Element Binding

In my previous post, I discussed the three modes of DataBinding for Windows 8. Today CheckBoxwe’ll take a brief look at binding not to data, but rather binding one UI element to the value of another.  In this example, we’ll bind the IsActive property of the ProgressRing to the IsChecked property’s value in a CheckBox. 

<StackPanel>
     <StackPanel
         Orientation="Horizontal"
         HorizontalAlignment="Left"
         >
         <TextBlock
             Text="ProgressRing:"
             VerticalAlignment="Center"
             Margin="0,0,20,0" />
         <Border
             BorderThickness="1"
             BorderBrush="#44000000"
             Padding="10">
             <ProgressRing
                 x:Name="ProgressRing1"
                 IsActive="{Binding IsChecked, 
                    ElementName=ActiveCB}" />
         </Border>
     </StackPanel>
     <CheckBox
         Name="ActiveCB"
         Content="Active?" />
 </StackPanel>

Notice that the IsActive property is bound to the IsChecked property and the ElementName (ActiveCB) is the Name of the CheckBox with that property. 

That’s it, there is no code associated with this example; just the XAML.

Share

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.
This entry was posted in Essentials. Bookmark the permalink.

4 Responses to Data Binding In Windows 8. Part 3–Element Binding

  1. Rajmohan says:

    Great article !! .

  2. Jeff Minch says:

    Interresting (at least to me), that the binding code is in the ProcessRing element and not the CheckBox element. Is there a reason for that? It seems if you wanted to bind several things to a property this could become problematic. Is there a way to put the binding code into the CheckBox element? I ask this from the perspective of a complete and utter noob to binding.

    Anyway, I want to take this opportunity to thank you for this series & your other writings. I’ve read about binding before and it always seems so useful but so intimidating. In your books and here you have a way of putting things in a manner that is both unintmidating and very understandable. Thank you.

  3. Pingback: Windows 8 Developer Links – 2012-08-17Dan Rigby | Dan Rigby

  4. Pingback: Data Binding and Element Binding In Windows 8 | azkafaiz.com

Leave a Reply

Your email address will not be published.