Windows Phone Data Binding between Elements using the Designer
published on: 2/17/2012 | Views: N/A | Tags: Beginners
by Waleed Arafa Al-Zoghby
In this article I'm going to talk about "Data Binding" between elements. I will use "Slider" & "TextBox" elements to clarify the idea.
Suppose that you have 2 elements a slider and a TextBox; and you want to bind the value of slider to the text property of textbox element so you will have a binding source: "Slider" and Binding target: "TextBox" .... it's easy....! Add an event handler "ValueChanged" of slider element and write one line of code like ' TextBox1.Text = Slider1.Value.ToString(); '... it's a traditional method to bind! But I want to demonstrate a feature supported by Silverlight for Windows Phone without adding an event handler.
We will create a new Windows Phone application and drag & drop a slider and TextBox elements on the current page like on the screenshot below. Next, select the TextBox and then "Apply Data Binding." from the Properties Window:
Next, select "Slider" as a binding source from the popup window:
After that select the property of the binding source(in our case "Value") and the type of the binding:
If you select "one-way" ... when you change the value of the slider, the textbox value will be changed. Otherwise, if you select "two-way" ... when you change the value of any element the other one will be affected as well.
Note: take a look at the binding of the Text property of the textbox element
<TextBox Height="72" HorizontalAlignment="Left" Margin="146,463,0,0" Name="textBox1" VerticalAlignment="Top" Width="156" TextAlignment="Center" Text="{Binding Path=Value, Mode=TwoWay, ElementName=slider1}" />
Solution attached.
You can also follow us on Twitter @winphonegeek
Comments
Windows Phone Data Binding between Elements using the Designer
posted by: Emmanuel Christopher on 2/19/2012 10:18:00 AM
Thank you.very useful.
Windows Phone Binding
posted by: Bharathi D :-) on 4/18/2012 1:33:53 PM
Simple Nice...
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
