<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-977035917106783448</id><updated>2024-09-06T01:43:38.784+01:00</updated><category term="Admin stuff"/><category term="DataBinding"/><category term="WPF"/><category term="c#"/><title type='text'>while(stupid)</title><subtitle type='html'>while(stupid)&lt;br&gt;&#xa;{&lt;br&gt;&#xa;    learn(stuff);&lt;br&gt;&#xa;}</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://whilestupid.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://whilestupid.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>nicknoodles</name><uri>http://www.blogger.com/profile/16057649575711087059</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-977035917106783448.post-8077547768686172702</id><published>2010-10-10T12:14:00.000+01:00</published><updated>2010-10-10T12:14:33.600+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Admin stuff"/><title type='text'>Feed Issues, Next Tutorial</title><content type='html'>Absolutely no idea why, but the feed refused to display the first tutorial. It was there in the XML for the feed, but Google Reader wouldn&#39;t show it. Anyway, through the standard IT technique of turning it off and turning it back on again I&#39;ve got it recognising the first post. Let&#39;s hope it still sees the others too.&lt;br /&gt;
&lt;br /&gt;
As for the next tutorial, I&#39;ve decided it&#39;s high time I did a beginner&#39;s guide to C#. It&#39;ll be fairly short in regards to code you&#39;ll be writing, but pretty long in explanation. Aiming at complete beginners is a tricky task for a writer, so it might face a few delays, but I&#39;m on track at the moment to have it out in time for the 1 post a month deadline.&lt;br /&gt;
&lt;br /&gt;
Hope to see you back again soon, tell your friends!&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;The Management&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://whilestupid.blogspot.com/feeds/8077547768686172702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://whilestupid.blogspot.com/2010/10/feed-issues-next-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/8077547768686172702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/8077547768686172702'/><link rel='alternate' type='text/html' href='http://whilestupid.blogspot.com/2010/10/feed-issues-next-tutorial.html' title='Feed Issues, Next Tutorial'/><author><name>nicknoodles</name><uri>http://www.blogger.com/profile/16057649575711087059</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977035917106783448.post-4771794154708057584</id><published>2010-09-29T17:42:00.001+01:00</published><updated>2010-09-29T17:44:33.775+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="DataBinding"/><category scheme="http://www.blogger.com/atom/ns#" term="WPF"/><title type='text'>A Basic Guide to WPF Databinding using Visual Studio and C#</title><content type='html'>Databinding is one of the most powerful tools the WPF framework provides. It allows a developer to abstract the user interface from the underlying mechanics of the system, removing the need for repetitive and boring assignment calls, type conversions and validation code on every control. The coder links a control&#39;s property to a field in an object or to a property on another control and everything else, all the assignments and &lt;i&gt;most &lt;/i&gt;conversions are handled for you.&lt;br /&gt;
&lt;br /&gt;
Read past the break for a simple guide to setting up a couple of bindings in Microsoft&#39;s Visual Studio and C#.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
To begin, create a new WPF application. We&#39;re going to create a basic form for inputting user details. Create some textboxes and a button at the bottom, go wild - make it beautiful, or if you&#39;re bored or in a rush, make it something like mine.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXBfSG1EC0Uo_dK0-95348m6d7quIGdSQ4TRnq7S0lRtrVYKtM4WGp-zOAt0YgvQIHS4sgfK_Q_iNoitKAACQ1kv_pxqadbPKP2-oXVqCKRm0Ll8yVaMD5YWW5xJI3aqbrwA-GyAR8sQ3Y/s1600/UI.jpg&quot; imageanchor=&quot;1&quot;&gt;&lt;img alt=&quot;A beautifully designed user interface with 5 textboxes and one button. Nothing stupid here, honest.&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXBfSG1EC0Uo_dK0-95348m6d7quIGdSQ4TRnq7S0lRtrVYKtM4WGp-zOAt0YgvQIHS4sgfK_Q_iNoitKAACQ1kv_pxqadbPKP2-oXVqCKRm0Ll8yVaMD5YWW5xJI3aqbrwA-GyAR8sQ3Y/s1600/UI.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Beautiful &lt;i&gt;and&lt;/i&gt; sensible.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
Next, create a new class; let&#39;s call it &quot;Person&quot; because imagination is the spice of life. Our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; class will hold our users&#39; data. Go ahead and add some fields that correspond to your interface. Mine looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt; class&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt;&amp;nbsp;firstName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt; surName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;int&lt;/span&gt; age;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;bool&lt;/span&gt; mollusc;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;char&lt;/span&gt; favLetter;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
It&#39;s almost time to make the magic happen, but first we need to do some messy bits. You see, databinding works by waiting until the source (one of our fields) updates before changing the linked interface element. At the moment any binding we were to set up would never know when the source had changed and nothing would happen. Let&#39;s rectify this by editing our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;&amp;nbsp;class. First, our class needs to implement the &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;INotifyPropertyChanged&lt;/span&gt;&amp;nbsp;interface, which is part of the &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #f9cb9c;&quot;&gt;System.ComponentModel &lt;/span&gt;package.&lt;br /&gt;
&lt;br /&gt;
Next, we create a public &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventHandler&lt;/span&gt; delegate; in fact let&#39;s make it an event too as it&#39;s only going to be called on property changes. We&#39;ll leave that there for now, shrouded in mystery and dripping in suspense, to write a function called &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #c27ba0;&quot;&gt;updateTarget&lt;/span&gt;&amp;nbsp;(or whatever you want really, it&#39;s a free country, unless you&#39;re reading this from inside a dictatorship, in which case you should probably name it &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #c27ba0;&quot;&gt;updateTarget&lt;/span&gt;). This function, whatever you&#39;ve called it, takes a string for its parameter. This string will be the name of the property that we&#39;re updating. What our function must first do is check that our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventHandler&lt;/span&gt; thingy isn&#39;t null, because otherwise we&#39;re in for a whole heap of exceptions. If it isn&#39;t null, which is the way things should be, then we should call it, passing in this as the sender and a new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventArgs&lt;/span&gt;, which gets our propertyName parameter as its parameter, our method being a kind and generous method. If you&#39;ve been paying attention your code should now look something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt; class&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt;&amp;nbsp;firstName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt;&amp;nbsp;surName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;int&lt;/span&gt;&amp;nbsp;age;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;bool&lt;/span&gt;&amp;nbsp;mollusc;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;char&lt;/span&gt;&amp;nbsp;favLetter;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;region&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;Stuff We Don&#39;t Need To See All The Time&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public event&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventHandler&lt;/span&gt; PropertyChanged;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;void&lt;/span&gt; updateTarget(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt; propertyName)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;if&lt;/span&gt; (PropertyChanged != &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyChanged(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventArgs&lt;/span&gt;(propertyName));&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;endregion&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
I&#39;ve also gone ahead and stuck that new code inside a region, this way we can hide it and keep it out of our way while the real code gets down to &lt;i&gt;bid&#39;niss&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&quot;So,&quot; I hear you say, &quot;We have some code that does absolutely nothing, our fields don&#39;t send updates and our UI just sits there, staring out of the window like a forlorn child.&quot;&lt;br /&gt;
&quot;Shut &lt;i&gt;up&lt;/i&gt;.&quot; I respond, &quot;We&#39;re getting there, and I think you might have some repressed memories you should probably see a shrink about.&quot;&lt;br /&gt;
&lt;br /&gt;
*Ahem*&lt;br /&gt;
&lt;br /&gt;
What we really need to do now is tell our code to call our fancy new method whenever it&#39;s updated. To do this we create public versions of all of the fields, and during the set routine, we make a call to updateTarget. Simple, right? I also explicitly stated that my original fields were private, mainly for neatness. Here&#39;s my code now:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt; class&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;private string&lt;/span&gt; firstName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;private string&lt;/span&gt; surName;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;private int&lt;/span&gt; age;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;private bool&lt;/span&gt; mollusc;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;private char&lt;/span&gt; favLetter;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;region&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;Stuff We Don&#39;t Need To See All The Time&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public event&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventHandler&lt;/span&gt;&amp;nbsp;PropertyChanged;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;void&lt;/span&gt;&amp;nbsp;updateTarget(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;string&lt;/span&gt;&amp;nbsp;propertyName)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(PropertyChanged !=&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PropertyChanged(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;this&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;new&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;PropertyChangedEventArgs&lt;/span&gt;(propertyName));&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;endregion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public string&lt;/span&gt; FirstName&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;get&lt;/span&gt; {&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;return&lt;/span&gt; firstName;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;set&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;firstName = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;updateTarget(&quot;FirstName&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public string&lt;/span&gt; SurName&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;get&lt;/span&gt; { &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;return&lt;/span&gt; surName; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;set&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;surName = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;updateTarget(&quot;SurName&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public int&lt;/span&gt; Age&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;get&lt;/span&gt; { &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;return&lt;/span&gt; age; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;set&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;age = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;updateTarget(&quot;Age&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public bool&lt;/span&gt; IsMollusc&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;get&lt;/span&gt; { &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;return&lt;/span&gt; mollusc; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;set&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mollusc = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;updateTarget(&quot;IsMollusc&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;public char&lt;/span&gt; FavouriteLetter&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;get&lt;/span&gt; { &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;return&lt;/span&gt; favLetter; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;set&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;favLetter = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #0b5394;&quot;&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;updateTarget(&quot;FavouriteLetter&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Aaaaaand that&#39;s all we need to do for our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; class, all done. Isn&#39;t that a relief, right? We retreat back into the warm and loving embrace of XAML, where &lt;i&gt;finally&lt;/i&gt;&amp;nbsp;we&#39;re going to set up these sexy bindings.&lt;br /&gt;
&lt;br /&gt;
Well, maybe not yet, but nearly.&lt;br /&gt;
&lt;br /&gt;
First we&#39;re going to add a little bit of XAML to help us. Y&#39;see, our XAML has absolutely no idea our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; class even exists at the moment, it&#39;s snubbing our poor little &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; like a snooty art critic in a black&amp;nbsp;turtle-neck&amp;nbsp;and half-moon sunglasses, sipping dry white wine and looking disgusted by everything it sees. This actually won&#39;t be an issue for us because once we&#39;ve set our created &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; object as the DataContext of the application (more on that later), it will know what to bind to, however we won&#39;t get any help from visual studio and we&#39;ll have to hope we didn&#39;t make any spelling mistakes.&lt;br /&gt;
&lt;br /&gt;
To start with, we need to show XAML what namespace we&#39;re using so it can be all impressed and go &quot;ooh!&quot; At the top of our XAML you&#39;ll see a load of lines that look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
These are the namespace declarations. The x namespace points to some XAML-specific functions. Well, we simply add another line underneath them, this time looking something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=&quot;clr-namespace:tut&quot;&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Where &quot;tut&quot; happens to be the namespace my &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; class resides in, and &quot;data&quot; is the label I&#39;ve given it. I don&#39;t recommend changing the rest as it&#39;s kind of important, you know?&lt;br /&gt;
&lt;br /&gt;
Nearly there! What with XAML being a declarative language and all, we should probably go ahead and &lt;i&gt;declare&lt;/i&gt;&amp;nbsp;our &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;&amp;nbsp;class. We do this in the DataContext, which is what the binding system will look to when it wants to know just what the &lt;i&gt;hell&lt;/i&gt;&amp;nbsp;you think you&#39;re talking about. Add the following code, just under the Window element at the top of your XAML:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Window.DataContext&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;data:Person&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=&quot;PersonData&quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Window.DataContext&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
This declares a Person, from the namespace known by the tag of &quot;data&quot; and gives it a name (PersonData) to XAML, so it can be referenced elsewhere. Go ahead and add &lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=&quot;mainWindow&quot;&lt;/span&gt;&lt;/code&gt; to the main Window element&#39;s attributes too, that way we can refer to it in code.&lt;br /&gt;
&lt;br /&gt;
DataContexts are inherited by child elements, unless those elements have their own DataContexts. This means every element in our window has access to our Person class, which is probably a bit of overkill. On a small test like this it doesn&#39;t really matter, but if you&#39;re making a Roaring Resource Raptor Reeling from Roid Rage™ you&#39;ll need all the spare cycles you can muster so it&#39;s best to set the DataContext as close to the elements that are using it as possible.&amp;nbsp;If a binding is looking for an object with a field called Awesome, and you&#39;ve neglected to set a DataContext, but there&#39;s a parent with a DataContext object that has that field, then that object will be bound to. It very well could be the wrong object, and bugs will ensue.&lt;br /&gt;
&lt;br /&gt;
Guess what! It&#39;s time for a Binding party! Now we can do this the easy way, or the hard way, but I&#39;ll show you both because I&#39;ve heard you internet folk can be greedy. We&#39;ll start with the hard way, which is coding by hand. Find one of the UI controls in your XAML (I&#39;m going with the textbox next to First Name:). Now work out which property you want to bind (I&#39;m binding the Text property, but you can bind almost any property on any control). Then, add that property as an attribute to the XAML tag. E.g. my Textbox becomes:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;TextBox&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
This is, of course, invalid XAML, as we still need to tell the TextBox what to put in its Text property. After the equals sign, we add the following:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;&quot;{&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Binding&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #e06666;&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;=FirstName}&quot;&lt;/span&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
What this does, is it tells the XAML to create a Binding. Now a Binding always assumes that the object you&#39;re binding to is the DataContext, unless you specify otherwise by using the Source field, which we&#39;ll cover some other time. The Path then tells it which field on this object you want to bind to, in my case, it&#39;s the FirstName field.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s try it out! If you&#39;ve jumped the gun and ran the code already you&#39;ll have noticed that absolutely nothing happened. Shows what &lt;i&gt;you&lt;/i&gt;&amp;nbsp;get for skipping ahead, dummy. That&#39;s because we can&#39;t see the object, so let&#39;s go ahead and change the value of our object&#39;s property in code, then our control will update automatic-like. &lt;i&gt;Magic&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Double click on the button you made earlier. Not made a button? Make one, and for future reference I &lt;i&gt;will&lt;/i&gt;&amp;nbsp;be obeyed. It will have automagically made you an event handler. In there we&#39;re going to put some simple code:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt; Person&lt;/span&gt; person = new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt;();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;person.Age = 18;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;person.FavouriteLetter = &#39;C&#39;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;person.FirstName = &quot;Lars&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;person.SurName = &quot;Rodriguez&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;person.IsMollusc = true;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mainWindow.DataContext = person;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Simple really, we create a new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #9fc5e8;&quot;&gt;Person&lt;/span&gt; object, fill in the properties and swap out the old DataContext (our declared PersonData) with it.&lt;br /&gt;
&lt;br /&gt;
Now if you run it you should find that when you click on the button the &quot;First Name:&quot; TextBox automatically updates to &quot;Lars&quot; or whatever name you chose. Maybe you used a celebrity&#39;s name, or maybe you used your own, you unimaginative halfwit.&lt;br /&gt;
&lt;br /&gt;
For the easy way, we&#39;ll bind the Age control. Select the TextBox next to the Age: label and then peruse the properties on the right hand side of the screen, look for the Text property. Have you found it yet? No? Keep looking! Ok, I&#39;m bored of that. Next to the word &quot;Text&quot; in the property screen there&#39;ll be a little nondescript box, hiding in plain sight. It will look a little something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBaFj6XCfr4v9FYnNFst7EspL3-U12AVOuO6FMTl_x-ew6TdxNmu4vx-PF81QWfJz9rivk37sPLrWzsbiLRzcPuD0ECRVpsVGi_FaQS4We_8VFQMiOKQP5-BIwoFaL2hcfZCjQU_ocN2dN/s1600/Properties.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBaFj6XCfr4v9FYnNFst7EspL3-U12AVOuO6FMTl_x-ew6TdxNmu4vx-PF81QWfJz9rivk37sPLrWzsbiLRzcPuD0ECRVpsVGi_FaQS4We_8VFQMiOKQP5-BIwoFaL2hcfZCjQU_ocN2dN/s400/Properties.jpg&quot; width=&quot;253&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Seriously Microsoft, how did you expect us to see &lt;i&gt;that&lt;/i&gt;?&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;If you click that a menu will pop up, allowing you to put special things in your properties, and what we want to add is, of course, a data binding so click &quot;Apply Data Binding...&quot;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;A new menu will come up and, thanks to our declaring the PersonData DataContext before, the Source will have automatically been set to PersonData and the Path window will be expanded. Here you will see a list of the available fields we can bind to. Double click on &quot;Age&quot; and you&#39;re done. You might notice that what this has actually done is written the XAML for us, so both methods are guaranteed to perform exactly the same. Build it and have a go!&lt;br /&gt;
&lt;br /&gt;
One final thing you really should know before venturing out alone in the brave new world of binding is that binding errors are silent assassins of CPU cycles. If a property has failed to bind, it will attempt to convert any bound field it has that matches the path. That takes time, but if it&#39;s unsuccessful it will then try to use a fallback. &lt;i&gt;If&lt;/i&gt;&amp;nbsp;there&#39;s no fallback it will create an exception, which we all know is a slow process, it will then trap the exception it created and report it to the Output log.&amp;nbsp;The tricky thing about WPF exceptions is that they only appear in the Output. They do&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;b&gt;not&lt;/b&gt;&amp;nbsp;halt the program when one is thrown, but they&amp;nbsp;&lt;b&gt;do&lt;/b&gt;&amp;nbsp;slow everything down a lot.&lt;br /&gt;
&lt;br /&gt;
You might have seen a few more options on that binding screen, but we&#39;ll save them for a more advanced binding tutorial, this is just the basics after all.&amp;nbsp;You&#39;ve now learnt two useful ways to bind data and all the necessary preparation required beforehand. Luckily most of this stuff is quite easy to remember after a couple of practises and soon becomes a much quicker way to build and maintain programs. Particularly when you factor in styled validation, converters, relative paths and template binding. But I&#39;ll save those for another day, nefarious tease that I am.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://whilestupid.blogspot.com/feeds/4771794154708057584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://whilestupid.blogspot.com/2010/09/basic-guide-to-wpf-databinding-using.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/4771794154708057584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/4771794154708057584'/><link rel='alternate' type='text/html' href='http://whilestupid.blogspot.com/2010/09/basic-guide-to-wpf-databinding-using.html' title='A Basic Guide to WPF Databinding using Visual Studio and C#'/><author><name>nicknoodles</name><uri>http://www.blogger.com/profile/16057649575711087059</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXBfSG1EC0Uo_dK0-95348m6d7quIGdSQ4TRnq7S0lRtrVYKtM4WGp-zOAt0YgvQIHS4sgfK_Q_iNoitKAACQ1kv_pxqadbPKP2-oXVqCKRm0Ll8yVaMD5YWW5xJI3aqbrwA-GyAR8sQ3Y/s72-c/UI.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-977035917106783448.post-3464530668955418777</id><published>2010-09-21T16:49:00.004+01:00</published><updated>2010-10-09T23:37:30.961+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Admin stuff"/><title type='text'>Welcome</title><content type='html'>Hi and welcome to &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;while&lt;/span&gt;(stupid). This site is blank at the moment while I get busy writing and formatting and editing and coding and partying too, because a balanced social life is important. I promise you though, when I&#39;ve gotten a nice backlog of articles written up I&#39;ll start posting them, and you&#39;ll be able to read them if you want. If you don&#39;t I&#39;m not sure there&#39;s much more I can do for you.&lt;br /&gt;
&lt;br /&gt;
For those of you who are interested in this sort of thing, and by that I mean &lt;i&gt;learnings&lt;/i&gt;, I&#39;ll start the whole caboodle off with a bang. A nice little guide to WPF databinding to make up for this paltry&amp;nbsp;place-holder you&#39;re putting up with for now. If you aren&#39;t interested in this sort of thing and you&#39;re still here then&amp;nbsp;you should probably go already, this is getting awkward.&lt;br /&gt;
&lt;br /&gt;
So I hope to see you all soon (apart from you disinterested peoples - just go, you&#39;ve broken my heart!) in a jiffy, or a while. However long it takes really.</content><link rel='replies' type='application/atom+xml' href='http://whilestupid.blogspot.com/feeds/3464530668955418777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://whilestupid.blogspot.com/2010/09/welcome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/3464530668955418777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/977035917106783448/posts/default/3464530668955418777'/><link rel='alternate' type='text/html' href='http://whilestupid.blogspot.com/2010/09/welcome.html' title='Welcome'/><author><name>nicknoodles</name><uri>http://www.blogger.com/profile/16057649575711087059</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>