<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pearl Tech &#187; RobB</title>
	<atom:link href="http://blog.pearltechnology.com/author/robb/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pearltechnology.com</link>
	<description></description>
	<lastBuildDate>Fri, 17 Feb 2012 17:35:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting out of a bind &#8212; with bindings</title>
		<link>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 12:12:52 +0000</pubDate>
		<dc:creator>RobB</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Bindings]]></category>
		<category><![CDATA[Converters]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=1152</guid>
		<description><![CDATA[Converters in WPF are quite possibly the most useful tool that I&#8217;ve used in the relatively short time I&#8217;ve spent developing WPF applications.  They give the ability to format data, style controls, and more, based on the value supplied from a binding.  And it doesn&#8217;t even have to be a binding to a data source.  [...]]]></description>
			<content:encoded><![CDATA[<p>Converters in WPF are quite possibly the most useful tool that I&#8217;ve used in the relatively short time I&#8217;ve spent developing WPF applications.  They give the ability to format data, style controls, and more, based on the value supplied from a binding.  And it doesn&#8217;t even have to be a binding to a data source.  You can bind to a property of another control on the page.  Lets take a look at a couple of examples.</p>
<p><span style="text-decoration: underline;">Setting a property based on a data value:</span></p>
<p>In this example, we have a label on a form that will display a dollar amount from our data source.  If the dollar amount is negative we want the label&#8217;s background to be red, and green if the value is positive.  To do this, we simply create a converter class in our code behind page.  This will use the numeric value and return a Brush object which we will use in our label&#8217;s Background property.  Here&#8217;s the code for the converter:</p>
<p style="text-align: center;"><img class="size-large wp-image-1153 aligncenter" title="cellbackgroundconverter" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/cellbackgroundconverter-1024x312.jpg" alt="cellbackgroundconverter" width="1024" height="312" /></p>
<p>We then have to create a simple reference to our converter class in our ResourceDictionary in the Window.Resources section of our XAML:</p>
<p><img class="alignnone size-full wp-image-1154" title="converterdefinition" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/converterdefinition.JPG" alt="converterdefinition" width="397" height="30" /></p>
<p>So far so good.  Now all we have to do is bind the label&#8217;s background property to the converter and data value.  Notice that we have to bind both the label&#8217;s content (text) and background to the Amount value from our data context.  We also can set the ContentStringFormat property to automatically format the value as currency:</p>
<p style="text-align: center;"><img class="size-full wp-image-1155 aligncenter" title="labelwithconverterbinding" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/labelwithconverterbinding.JPG" alt="labelwithconverterbinding" width="709" height="39" /></p>
<p><span style="text-decoration: underline;">Setting a property based on another control&#8217;s property:</span></p>
<p>This method is useful when there isn&#8217;t a data field to bind to, but there is a need to conditionally set a control&#8217;s property.  Let&#8217;s assume we need to set a button control&#8217;s IsEnabled property based on a check box&#8217;s IsChecked property:</p>
<p style="text-align: center;"><img class="size-full wp-image-1158 aligncenter" title="bindingtocontrolproperties" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/bindingtocontrolproperties1.JPG" alt="bindingtocontrolproperties" width="754" height="144" /></p>
<p>As you can see, we&#8217;ve bound the IsEnabled property of the buttons to the IsChecked property of  the check box by specifying the ElementName (control&#8217;s name) and Path (control&#8217;s property).  We also bound the Content property of the button to the same IsChecked property using the same method, to show the current state of the button (which the framework automatically converts from a boolean to a string).  The best part about this method?  No code behind!  Here&#8217;s the result:</p>
<p style="text-align: center;"><img class="size-full wp-image-1159 aligncenter" title="bindingtocontrolpropertiesresult" src="http://blog.pearltechnology.com/wp-content/uploads/2011/04/bindingtocontrolpropertiesresult.JPG" alt="bindingtocontrolpropertiesresult" width="115" height="101" /></p>
<p style="text-align: left;">This is a very simple overview of the power of converters and bindings, and how they can be used to help you do more than just display the data on your page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/getting-out-of-a-bind-with-bindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF and MDI</title>
		<link>http://blog.pearltechnology.com/wpf-and-mdi/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/wpf-and-mdi/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 15:58:13 +0000</pubDate>
		<dc:creator>RobB</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[MDI]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=927</guid>
		<description><![CDATA[On a current Windows application we made the decision to use Windows Presentation Foundation (WPF) instead of the time-tested Windows Forms.  The main consideration was styling, because seriously, who wants an application that looks like Windows 95?
However, the project required a multiple document interface (MDI), which is not supported in WPF.
After some quick thinking, I [...]]]></description>
			<content:encoded><![CDATA[<p>On a current Windows application we made the decision to use Windows Presentation Foundation (WPF) instead of the time-tested Windows Forms.  The main consideration was styling, because seriously, who wants an application that looks like Windows 95?</p>
<p>However, the project required a multiple document interface (MDI), which is not supported in WPF.</p>
<p>After some quick thinking, I decided to try using the Windows Forms MDI while creating the WPF forms as individual WPF User Controls, and embedding them into individual Windows Forms inside the ElementHost control.  Sounds easy, right?  Well actually, it was.  In this example, I&#8217;m using Visual Studio 2010.</p>
<p>For example, you have a lookup form containing a textbox for entering a User ID and a button which needs to launch a new form which does a database pull and displays the user’s details.  I know you&#8217;re asking: &#8220;Why don&#8217;t you put the lookup on the same form as the results?&#8221;  Well, yes, that sounds more reasonable.  But it doesn&#8217;t help me make my example about communicating between WPF forms in the Windows Forms MDI, ok?</p>
<p>In your Windows Forms project, after adding an MDI Parent Form, create two new forms: one called FrmLookup and the other called FrmDetails.</p>
<p>Then, add two new WPF User Controls to your project, called WpfLookup and WpfDetails.  My WpfLookup control (design view) looks something like this:</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/01/wpf1.png" alt="" /></p>
<p>The WpfDetails control (design view) will look like this:</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/01/wpf2.png" alt="" /></p>
<p>Add an ElementHost control to each of the forms and set the Hosted Content (or Child) of the control to the appropriate WPF control.  The WPF control will then render in your Windows Form.</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/01/wpf31.png" alt="" /></p>
<p>So now, it’s time to wire up the events to pass the User ID value from the text box to the details form.  In the WpfLookup control’s code behind, we will add the following code, which instantiates an event which we can see from the FrmLookup and contains the User ID value:</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/01/wpf4.png" alt="" /></p>
<p>We will need to add a handler for the event in the Load event of FrmLookup.  The handler will call a function to launch the Details form inside the MDI parent form when the OnButtonClicked event is triggered in the WPF control. The code in FrmLookup will look like this:</p>
<p><img src="http://blog.pearltechnology.com/wp-content/uploads/2011/01/wpf5.png" alt="" /></p>
<p>Now you can use the User ID value passed to the Details form to populate its controls.  I won’t go into how to do that.  I’ll save the WPF data binding for another topic, but at least now you have pretty WPF forms inside a multiple document interface!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/wpf-and-mdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

