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.

http://ssccinc.com/wpfdatabinding.zip

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
      • <TextBlock Text="{Binding ElementName=mySourceElement,Path=Text }" Grid.Row="2" />

        Here is the entire XAML

            <Grid  >  
                <Grid.RowDefinitions >
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <TextBox Name="mySourceElement" Grid.Row="0"
                         TextChanged="mySourceElement_TextChanged">Hello Orlnado</TextBox>
                <TextBlock Grid.Row="1">           
                    <TextBlock.Text>
                        <Binding ElementName="mySourceElement" Path="Text"  />
                    </TextBlock.Text>
                </TextBlock>
                <TextBlock Text="{Binding ElementName=mySourceElement,Path=Text }" Grid.Row="2" />
            </Grid>
        </Window>

  • 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.
    • <Grid>
           <Grid.RowDefinitions >
               <RowDefinition Height="40px" />
               <RowDefinition Height="40px" />
               <RowDefinition Height="*" />
           </Grid.RowDefinitions>
           <Slider Name="fontSizeSlider" Minimum="5" Maximum="100"
                   Value="10" Grid.Row="0" />
           <TextBox Name="SizeTextBox"     
                    Text="{Binding ElementName=fontSizeSlider, Path=Value}" Grid.Row="1"/>
           <TextBlock Text="Example 01"
                      FontSize="{Binding ElementName=SizeTextBox,  Path=Text}"  Grid.Row="2"/>
      </Grid>

  • Example02
    • very much like the previous example but it also has a font dropdown
    • <Grid>
           <Grid.RowDefinitions >
               <RowDefinition Height="20px" />
               <RowDefinition Height="40px" />
               <RowDefinition Height="40px" />
               <RowDefinition Height="*" />
           </Grid.RowDefinitions>
           <ComboBox Name="FontNameList" SelectedIndex="0" Grid.Row="0">
               <ComboBoxItem Content="Arial" />
               <ComboBoxItem Content="Calibri" />
               <ComboBoxItem Content="Times New Roman" />
               <ComboBoxItem Content="Verdana" />
           </ComboBox>
           <Slider Name="fontSizeSlider" Minimum="5" Maximum="100" Value="10" Grid.Row="1" />
           <TextBox Name="SizeTextBox"      Text="{Binding ElementName=fontSizeSlider, Path=Value}" Grid.Row="2"/>
           <TextBlock Text="Example 01" FontFamily="{Binding ElementName=FontNameList, Path=Text}"
                      FontSize="{Binding ElementName=SizeTextBox,  Path=Text}"  Grid.Row="3"/>
      </Grid>

  • 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
    • <Grid DataContext="{StaticResource MyEmployee}">
              <Grid.RowDefinitions>
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="*" />
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions >
                  <ColumnDefinition Width="130px" />
                  <ColumnDefinition Width="178*" />
              </Grid.ColumnDefinitions>

          </Grid>

    • and Finally we have textboxes that will bind to that textbox
    •          <Label Grid.Row="0" Grid.Column="0">Employee Number</Label>
              <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=EmployeeNumber}"></TextBox>
              <Label Grid.Row="1" Grid.Column="0">First Name</Label>
              <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=FirstName}"></TextBox>
              <Label Grid.Row="2" Grid.Column="0">Last Name</Label>
              <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=LastName}" />
              <Label Grid.Row="3" Grid.Column="0">Title</Label>
              <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Title}"></TextBox>
              <Label Grid.Row="4" Grid.Column="0">Department</Label>
              <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=Department}" />
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Sunday, April 04, 2010 9:31 AM

Comments on this post

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I think this is a wonderful idea to talk about it.
Left by Watches on Feb 05, 2011 4:08 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Proper Footwear choice is very crucial while doing any workouts...And You made some good points there.
Left by phoenix photographer on Feb 13, 2011 11:35 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I discovered a lot of interesting stuff in your blog particularly it's discussion. From the tons of remarks on your articles, I suppose I am not the only one having all of the enjoyment here! keep up the good work.
Left by Farm Tractors on Feb 24, 2011 5:03 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Very interesting article.Content has been written in very nice manner.I enjoy reading this kind of stuff.Thanks for sharing good knowledge.
Left by Automobile Shippers on Feb 28, 2011 6:42 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
This is a very fascinating post,I was looking for this info.All information found here is genuine and realistic.
Left by 2 Sim on Mar 01, 2011 5:31 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I completely agree with you on all points and I am thinking about adding a link on my blog to your blog post because its that good.
Left by Medical ISO on Mar 05, 2011 11:23 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I've been looking over your shoulders for quite a while now. And I feel now is the time for a more extensive comment.
Left by World Lotteries Association on Mar 05, 2011 11:24 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I feel like you could probably teach a class on how to make a great blog. This is fantastic I have to say, what really got me was your design. You certainly know how to make your blog.
Left by los angeles lipo on Mar 07, 2011 6:11 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Interesting post and thanks for sharing. Some things in here I have not thought about before.Garage Conversion Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.Attic Conversion
Left by anokhi on Mar 15, 2011 5:56 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
It is so interesting!!! I've read something of the kind, but this article made me understand much more!
Left by Free Downloads on Apr 02, 2011 2:27 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I do not think I have read anything like this before. So good to find somebody with some original thoughts on this subject. Thanks for starting this up.
Left by Swimwear on Apr 03, 2011 12:31 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us
Left by IPL 2011 on Apr 04, 2011 11:33 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
This is such an informative website. I am looking forward to future updates. Thank you for the post.
Left by Software Download on Apr 09, 2011 3:37 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I must say i loved the way you have created your website, its simple, neat, simple to navigate and extremely easy on the eyes. Are you able to let me know which theme or designer did you use.
Left by Bare Lifts on Apr 24, 2011 11:46 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks for providing a great information
Left by commodity broker on Apr 27, 2011 4:44 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
interesting stuff.
Left by storefront queens on Apr 30, 2011 5:16 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
veyr good stuff.
Left by glass manhattan on Apr 30, 2011 5:16 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks a lot for sharing that to us buddy.This is really great.
Left by real estate toronto on May 16, 2011 11:55 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Nice code. But I am not able to download the zip file. Can u please reupload the file.
Left by golf simulator on May 24, 2011 1:24 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
useful code. I can't download the zip file too.
Left by convert mkv to avi on May 27, 2011 11:51 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Great work. You do help me a lot,thank you.
Left by convert mkv to avi on May 27, 2011 11:52 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I wouldn't agree with everything in this written piece, but you do make some very good points. Regardless it absolutely was a well thought out and great read therefore i decided I would leave you a comment.
Left by cityville help on May 28, 2011 7:01 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
this is interesting. good stuff.
Left by pex plumbing on Jun 17, 2011 2:13 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
good article.
Left by pex on Jun 23, 2011 3:49 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
this is very interesting. good post.
Left by pex on Jun 23, 2011 3:50 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I have found the solution to the problem I was facing. Thanks a lot for keeping this blog and providing us with great and useful content.
business credit
Left by Jenny on Jul 07, 2011 9:27 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Another useful post - thanks so much!

Content Writer
Left by Website Content Writer on Jul 12, 2011 11:44 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks for posting advanced databinding presentation from South Florida Code camp and also Orlando Code camp. I went on to the website to check the demos too.
We Buy Houses in Denver
Left by Hailey on Jul 15, 2011 10:54 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I am looking for the 2 other blog posts related to this post. I couldn't find them before. I might have a look once more though.
Cut the Rope Walkthrough
Left by Kenzie on Jul 18, 2011 5:28 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks for sharing this such interesting article and I really appreciate it, I hope that you post more interesting article here. pmp training pmp exam prep
Left by florcajes on Jul 22, 2011 2:27 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks for sharing this article, You really help me Hope you keep updating this site, pmp exam questions pmp practice exam
Left by jeffreyhoward on Jul 24, 2011 9:09 PM

# WPF Databinding- Not your fathers databinding Part 1-

Requesting Gravatar...
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog
Left by Home Renovations Services New Ca on Jul 25, 2011 3:35 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
yeah.. this sounds so awesome buddy., i really appreciate it.
Left by evergreen business system review on Jul 29, 2011 11:02 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
A bit confusing but wanna bookmark and read the whole thing
Left by Gopinath on Aug 08, 2011 1:57 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I have been able to get a solution to a lot of coding problems over 6 months. I'm working towards collecting facts about India that I can put out on my website. Thanks a lot for that!
Left by Jenny on Aug 20, 2011 11:27 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I am looking forward to master all the techniques of this hard coding. I am so glad there good people sharing their knowledge. Thank you.
Left by Austin Wellness Center on Aug 21, 2011 6:40 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I find your post really great and interesting. Also i highly appreciated your done. Keep on. I hope you will bring more good reading to us. I've bookmark your site and i will send it to my friends. I think they will be glad to pick up your site...

free cell phone spy software
Left by salariarice on Aug 25, 2011 2:09 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
yes, it is something important, to understand the code if you wish to work on improving the programs. Why do you invest in it? probably because you like it!
Left by Projekty Tanich Domow on Aug 29, 2011 1:35 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Would be awesome to get help of you on such hard to find topics. It's just been few months I've got myself into creating websites and such so I developed some interesting facts about India list that provides some unknown facts that people do not know about.
Left by nimen on Sep 02, 2011 12:24 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Really very handy. I've again and again been looking into my wpf book for this, but yours is much more compact and complete. Wireless Doorbell
Left by ginger rhain on Oct 11, 2011 4:51 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
aah huge but will try to make on it
Left by john jeo on Nov 02, 2011 1:19 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
use full topic but a bit confused
Left by aasha on Nov 02, 2011 1:24 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I found some great information on this web site while i was searching web about how to teach reading i noticed some interesting facts which i would like to share with you all.
Left by Johansson on Nov 07, 2011 2:32 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
This is very much satisfied by the different info is visible in this blog. I am really admired for using the nice services in this blog that to sharing the nice approach in this blog.
Left by server job description on Nov 17, 2011 1:28 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Your post is really good and informative. I'm surprised that your post has not gotten any good quality, genuine comments. You have done a great job by posting this article.buy essay online
professional essay writers
Left by hunny on Dec 02, 2011 6:05 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I love this site. XD
Left by Retirement Planning on Dec 05, 2011 11:15 AM

# Behavioral Problems in Children

Requesting Gravatar...
Very nice applets and navigation of this site, i want to share some information about Behavioral Problems in Children the content available on this website behavior problems in children are very much beneficial for the people who are searching about this.
Left by Soham on Dec 06, 2011 1:23 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
thanks for the post, still a little confusing to me
Left by Minneapolis Injury Lawyer on Dec 21, 2011 2:51 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Many interesting information. I like very much this article,good job. Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative,
Left by Pariuri live on Dec 27, 2011 7:38 PM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I really increased my knowledge after read your post which will be beneficial for me.
Left by articles about health on Jan 14, 2012 6:08 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Thanks you very much for posting.
Finance and Stuff
Top Finance Blog
Left by Finance 101 on Jan 20, 2012 2:52 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Mountain Trek in British Columbia and Mexico are health retreats that specialize in weight loss spa vacations.Find out why we are rated one of the top weight loss retreats in the world.

Left by Jennifer Roy on Jan 21, 2012 3:41 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
IBSM Kolkata- full time mba in Kolkata, read full time MBA courses from best international business school of management.IBSM provide Finance Management, Marketing Management, Human Resource Management, Retail Business Management, Operations and Supply Chain Management in area of specialization in full time mba in Kolkata.
Left by full time mba in kolkata on Feb 02, 2012 2:44 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
I like very scads this article,good job. Thank you so scads for the siting you do. I like your post and all you share with us is up to date and quite informative...
Left by stairs in aurora on Feb 09, 2012 7:04 AM

# re: WPF Databinding- Not your fathers databinding Part 1-3

Requesting Gravatar...
Many interesting information. it is something important, to understand the code if you desire to vocation on shining the programs. Why do you invest in it? probably because you like it Pakistani Food Delivery in Mississauga!
Left by Nice Boy ! on Feb 09, 2012 7:07 AM

Your comment:

 (will show your gravatar)