Geeks With Blogs
Welcome to
Geeks with Blogs
Login
Mamta M
25 Posts
| 13 Comments
My Other Recent Posts
More links
Awesome game developed in Silverlight
How to use line breaks in TextBlock controls
How to change default browser in Silverlight applications
WPF Binding Mode
Let's have a ball (watch)!!
A few recent msdn blogs on Silverlight
Did you know?
Design Time Formatting of RichTextBox in Silverlight 4
Using DatePicker control in Silverlight
Post Categories
xna
C#
silverlight
general
wp7
tutorial
quicktips
review
VB
directx
C++
Archives
October 2011 (3)
July 2011 (2)
April 2011 (2)
November 2010 (1)
September 2010 (1)
August 2010 (1)
July 2010 (15)
Silverlighting...
Ramblings on Silverlight and occasionally WPF
<< Let's have a ball (watch)!!
|
Home
|
How to change default browser in Silverlight applications >>
WPF Binding Mode
Comments (1)
|
Share
WPF Binding Mode
Apart from the default binding, which is one way, you can also configure binding to be two way, one way to source, and so forth. This is done by specifying the
Mode
property.
OneWay
: Causes changes to the source property to automatically update the target property but the source does not get changed
TwoWay
: Changes in the source or target automatically cause updates to the other
OneWayToSource
: Causes changes to the target property to automatically update the source property but the target does not get changed
OneTime
: Causes only the first time change to the source property to automatically update the target property but the source does not get changed and subsequent changes do not affect the target property
Two way binding with TextBox
Let us now consider an example that demonstrates two-way data binding with a TextBox. In this example, a ListBox containing a set of routes is created in XAML. A TextBox control is bound to this ListBox using the following code:
<TextBox Text="{Binding ElementName=Routes, Path=SelectedItem.Content, Mode=TwoWay}">
Here, we have specified the binding source, the path to bind to, and the binding mode. Because the binding mode is set to two way, any changes made to the TextBox are automatically reflected in the
ListBox
. Two way binding means that changes made to the bound control result in updates to the source and vice versa.
The complete XAML code for this example is listed below:
<Window x:Class="UpdateDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="210" Width="298">
<Grid Width="231">
<Grid.RowDefinitions>
<RowDefinition Height="52*" />
<RowDefinition Height="52*" />
<RowDefinition Height="52*" />
<RowDefinition Height="33*" />
<RowDefinition Height="71*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBox x:Name="Routes" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Background="Azure">
<ListBoxItem Content="LA"/>
<ListBoxItem Content="Mexico"/>
<ListBoxItem Content="SF"/>
<ListBoxItem Content="Au"/>
</ListBox>
<TextBox Text="{Binding ElementName=Routes, Path=SelectedItem.Content, Mode=TwoWay}" Background="LightSteelBlue" Grid.Column="1" Margin="0,13,-1,0" Grid.Row="2" Grid.RowSpan="2">
</TextBox>
</Grid>
</Window>
Posted on Sunday, July 4, 2010 9:33 AM
WPF
|
Back to top
Related Posts on Geeks With Blogs
Matching Categories
Wpf TreeView MVVM view model
WPF
Processing Kinect v2 Color Streams in Parallel
WPF
Setting a WPF Image programmatically
WPF
Always open XAML files in full XAML view
WPF
Proxy Swarm
WPF
Comments on this post: WPF Binding Mode
#
re: WPF Binding Mode
This is crisp and clear information which explains about Mode details
Left by
Chandra
on May 16, 2012 10:54 AM
Your comment:
Title:
Name:
Email: (never displayed)
(will show your
gravatar
)
Comment:
Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
Verification:
Copyright © Mamta | Powered by:
GeeksWithBlogs.net
Popular Posts on Geeks with Blogs
0
Code Monkey Projectiles - Index
Kindle days are gone and amazon is not gonna accept it.
Geeks With Blogs Content Categories
ASP.Net
SQL Server
Apple
Google
SharePoint
Windows
Visual Studio
Team Foundation Server
Agile
Office
Design Patterns
Web
Azure
Brand New Posts on Geeks with Blogs
0
Kindle days are gone and amazon is not gonna accept it.
How do you run multiple instances of Microsoft Teams?
Benefits of Apple Cider Vinegar
Shaking down the Raspberry Pi 400
Blog is Moving