WPF Databinding- Not your fathers databinding Part 1-3

As Promised here is my advanced databinding presentation from South Florida Code camp and also Orlando Code camp. you can find the demo files here.

Here is a quick description of the first demos, there will be 2 other Blogposting in the next few days getting into more advance databinding topics.

  • Example00

  • Here we have 3 textboxes,

  • The first textbox mySourceElement

  • Second textbox has a binding to mySourceElement and Path= Text

<Binding ElementName="mySourceElement" Path="Text"  />

  • Third textbox is also bound to the Text property but we use inline Binding

Here is the entire XAML

    <Grid  >           <Grid.RowDefinitions >                                             </Grid.RowDefinitions>         <TextBox Name="mySourceElement" Grid.Row="0"                  TextChanged="mySourceElement_TextChanged">Hello Orlnado                                 <TextBlock.Text>                 <Binding ElementName="mySourceElement" Path="Text"  />             </TextBlock.Text>                    

  • Example01

  • we have a slider control, then we have two textboxes bound to the value property of the slider. one has its text property bound, the second has its fontsize property bound.

                                                   
  • Example02

  • very much like the previous example but it also has a font dropdown

                                                                                                          
  • Example03

  • In this example we bind to an object Employee.cs

  • Notice we added a directive to our xaml which is clr-namespace and the namespace for our employee Class

xmlns:local="clr-namespace:Example03"

  • In Our windows Resources we create an instance of our object

<Window.Resources>     <local:Employee x:Key="MyEmployee" EmployeeNumber="145"                     FirstName="John"                     LastName="Doe"                     Department="Product Development"                     Title="QA Manager" />

</Window.Resources>

  • then we bind our container to the that instance of the data
                                                                                                                   

   

  • and Finally we have textboxes that will bind to that textbox          Employee Number                 First Name                 Last Name                 Title                 Department        
This article is part of the GWB Archives. Original Author: Shervin Shakibi

New on Geeks with Blogs