<?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>dandesousa.com &#187; Programming</title>
	<atom:link href="http://dandesousa.com/category/technical/feed/" rel="self" type="application/rss+xml" />
	<link>http://dandesousa.com</link>
	<description>// a resource on anything</description>
	<lastBuildDate>Tue, 31 Aug 2010 02:30:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Windows Phone 7: Making an HTTP Request</title>
		<link>http://dandesousa.com/2010/08/30/windows-phone-7-making-an-http-request/</link>
		<comments>http://dandesousa.com/2010/08/30/windows-phone-7-making-an-http-request/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 02:20:46 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://dandesousa.com/2010/08/30/windows-phone-7-making-an-http-request/</guid>
		<description><![CDATA[Silverlight and the Windows Phone 7 SDK include the standard System.Net packages for making various requests over ftp and http. Making a standard http request in C# involves setting up a number of delegates and asynchronous callbacks for getting http responses and can be a tad complicated. If you simply want to get some xml [...]]]></description>
			<content:encoded><![CDATA[<p>Silverlight and the Windows Phone 7 SDK include the standard System.Net packages for making various requests over ftp and http. Making a standard http request in C# involves setting up a number of delegates and asynchronous callbacks for getting http responses and can be a tad complicated. If you simply want to get some xml or html back as a string over http, it’s much easier to use the simpler, more abstract WebClient class. Here’s an example of using the WebClient class to make a request.</p>
<pre class="brush: csharp;">
public void getResults(string websiteURL)
{
  WebClient c = new WebClient();
  c.DownloadStringAsync(new Uri(websiteURL));
  c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(c_DownloadStringCompleted);
}

void c_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
  lock (this)
  {
    string s = e.Result;
    XmlReader r = XmlReader.Create(new MemoryStream(System.Text.UnicodeEncoding.Unicode.GetBytes(s)));
    // So something with the XML we get back
  }
}
</pre>
<p> So basically all we do is say download the string and make the action to take when it is completed as c_DownloadStringCompleted event handler. You may want to do something different than place it in an xml reader (in this case the string we are getting back corresponds to a non-xhtml xml file. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/30/windows-phone-7-making-an-http-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7: ListBox Item Horizontal Width Stretch</title>
		<link>http://dandesousa.com/2010/08/29/windows-phone-7-listbox-item-horizontal-width-stretch/</link>
		<comments>http://dandesousa.com/2010/08/29/windows-phone-7-listbox-item-horizontal-width-stretch/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 21:15:52 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://dandesousa.com/2010/08/29/windows-phone-7-listbox-item-horizontal-width-stretch/</guid>
		<description><![CDATA[I have spent most of the day today working on a Windows Phone 7 app I hope to have ready for launch this fall / winter. I figured that adoption of the platform and generation of apps is good for all of us as it generates hype for the platform and facilitates development. So I [...]]]></description>
			<content:encoded><![CDATA[<p>I have spent most of the day today working on a Windows Phone 7 app I hope to have ready for launch this fall / winter. I figured that adoption of the platform and generation of apps is good for all of us as it generates hype for the platform and facilitates development. So I will be sharing all the gotcha’s and particularly frustrating experiences (and there solutions here!).</p>
<p>In WP7, if you try to use a ListBox control, you’ll noticed that child controls do not completely fill the available space of the control. To do this you have to override the style of the ListBox’s ItemContainer, as well as override the template and set the appropriate HorizontalContentAlignment properties.</p>
<p>First, this is what the problem looks like. In blue we have the entire ListBox Control, and in white is the space for an individual item.</p>
<h2>The Problem</h2>
<h2>&#160;</h2>
<h2>&#160;</h2>
<h2><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/problem.png"><font color="#4265a7"></font><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="problem" border="0" alt="problem" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/problem_thumb.png" width="293" height="544" /></a></h2>
<p>As you can see, the ListBoxItem is shown in white and only fits the size of the content. The entire ListBox is shown in red and remains empty. If you increase the size of the text it will stretch to the width. But if we wanted to align the button on the right as its own column we want the text to take up the remaining space and we need the item to fit the width of the control. Then we’d be able to use a Grid control to set the proper alignment.</p>
<h2>The Solution</h2>
<p>We have to override not only the HorizontalContentAlignment Properties of the ItemContainer but also pass those onto the Template and Container in the Style. This is very unintuitive as you would expect HorizontalContentAlignment to just work.</p>
<pre class="brush: xml;"> &lt;phone:PhoneApplicationPage.Resources&gt;          &lt;Style x:Key=&quot;ListBoxItemStyle1&quot; TargetType=&quot;ListBoxItem&quot;&gt;
            &lt;Setter Property=&quot;Background&quot; Value=&quot;Transparent&quot;/&gt;
            &lt;Setter Property=&quot;BorderThickness&quot; Value=&quot;0&quot;/&gt;
            &lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;Transparent&quot;/&gt;
            &lt;Setter Property=&quot;Padding&quot; Value=&quot;0&quot;/&gt;
            &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Stretch&quot;/&gt;
            &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Stretch&quot; /&gt;
            &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Stretch&quot;/&gt;
            &lt;Setter Property=&quot;Template&quot;&gt;
                &lt;Setter.Value&gt;
                    &lt;ControlTemplate TargetType=&quot;ListBoxItem&quot;&gt;
                        &lt;Border x:Name=&quot;LayoutRoot&quot; BorderBrush=&quot;{TemplateBinding BorderBrush}&quot; BorderThickness=&quot;{TemplateBinding BorderThickness}&quot; Background=&quot;{TemplateBinding Background}&quot; HorizontalAlignment=&quot;{TemplateBinding HorizontalAlignment}&quot; VerticalAlignment=&quot;{TemplateBinding VerticalAlignment}&quot;&gt;
                            &lt;ContentControl x:Name=&quot;ContentContainer&quot; ContentTemplate=&quot;{TemplateBinding ContentTemplate}&quot; Content=&quot;{TemplateBinding Content}&quot; Foreground=&quot;{TemplateBinding Foreground}&quot; HorizontalContentAlignment=&quot;{TemplateBinding HorizontalContentAlignment}&quot; Margin=&quot;{TemplateBinding Padding}&quot; VerticalContentAlignment=&quot;{TemplateBinding VerticalContentAlignment}&quot;/&gt;
                        &lt;/Border&gt;
                    &lt;/ControlTemplate&gt;
                &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
        &lt;/Style&gt;      &lt;/phone:PhoneApplicationPage.Resources&gt; </pre>
<p>Then apply it to the ListBox:</p>
<pre class="brush: xml;"> &lt;ListBox x:Name=&quot;SearchResultsListBox&quot;
                     Grid.Row=&quot;0&quot;
                     HorizontalContentAlignment=&quot;Stretch&quot;
                     ItemContainerStyle=&quot;{StaticResource ListBoxItemStyle1}&quot;
                     ItemsSource=&quot;{Binding ElementName=SearchPageControl, Path=QueryHandler.OpenSearchSuggestion.section.items, Mode=OneWay}&quot;&gt;  ... </pre>
<h2>The Result</h2>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/solved.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="solved" border="0" alt="solved" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/solved_thumb.png" width="289" height="541" /></a> </p>
<p>As you can see the item wrapped in white stretches the entire width of the ListBox in red.</p>
<h2>Conclusions</h2>
<p>Although unintuitive this should get the job done. Hopefully Microsoft can make some of these details more straightforward before the final release or in updated versions of .NET. </p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/29/windows-phone-7-listbox-item-horizontal-width-stretch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Memory Leaks in .NET Using SOS.dll and Visual Studio</title>
		<link>http://dandesousa.com/2010/08/28/finding-memory-leaks-in-net-using-sos-dll-and-visual-studio/</link>
		<comments>http://dandesousa.com/2010/08/28/finding-memory-leaks-in-net-using-sos-dll-and-visual-studio/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 04:31:21 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=665</guid>
		<description><![CDATA[Often, after finishing a major feature or wrapping up an application. You are faced with the challenge of tracking down memory leaks. Memory leaks occur when you allocate memory for an object, then lose track of the reference or overwrite the reference to that memory without freeing the memory in your application (essentially losing or [...]]]></description>
			<content:encoded><![CDATA[<p>Often, after finishing a major feature or wrapping up an application. You are faced with the challenge of tracking down memory leaks. Memory leaks occur when you allocate memory for an object, then lose track of the reference or overwrite the reference to that memory without freeing the memory in your application (essentially losing or “leaking” memory). In the context of C#, a memory leak is different since you don’t typically explicitly free an object you allocate. In C# a memory leak occurs when you allocate an object and then hold onto it without actually intending to. Finding the leak can be extraordinarily difficult in a large application. Luckily, Microsoft provides us with an extension to the debugger which allows us to inspection the code. This is known as SOS.dll (Son of Strike). First, locate the SOS.dll file on your machine. You can do it by opening up a search window on your windows drive or wherever the .NET framework is installed, and searching for SOS.dll:</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/sossearch1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="sossearch" border="0" alt="sossearch" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/sossearch_thumb1.png" width="454" height="310" /></a> </p>
<p>You’ll want the dll which pertains to your version and binary type (in my case I want the path referring to v4.030319 and non-64bit). </p>
<p>Next we’ll open up our application in visual studio and start the debugger.First you need to enable unmanaged debugging. So right click on your project and go to properties. You should see a window similar to the one below. Select debugging and make sure the circled checkbox is enabled:</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/enabledebug1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="enabledebug" border="0" alt="enabledebug" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/enabledebug_thumb1.png" width="454" height="296" /></a> </p>
<p> Run your application and wait until the point you want to check your memory usage. You’ll want to look for the pause button or hit CTRL+BREAK to break the running of your application.</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/pause1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="pause" border="0" alt="pause" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/pause_thumb1.png" width="454" height="66" /></a> </p>
<p>Next, open the immediate window or go to <strong>Debug-&gt;Windows-&gt;Immediate Window</strong> to bring it up.</p>
<p>Now, you’ll want to load SOS.dll to access the extensions, we do this with the load command in below:</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/load1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="load" border="0" alt="load" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/load_thumb1.png" width="454" height="154" /></a> </p>
</p>
<p>Ok, now we can issue commands to find out information about our system. Type in “!dumpheap” to get a list of all the allocated objects on the heap. Be careful though, you can easily overwhelm your system with output. To summarize and get only the useful information type “!dumpheap –stat”. You see something like this:</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/dumpheapstat1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="dumpheapstat" border="0" alt="dumpheapstat" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/dumpheapstat_thumb1.png" width="454" height="326" /></a> </p>
<p>The columns in order are, method table, number of instances in memory, total size of instances, type.</p>
<p>!dumpheap has a ton of flags. If you use !dump –type System.String, you can get a summary of all heap objects matching the type (in this case, System.String). Not that the method table is not the same as the memory address. Say we wanted to find out what was holding one of the dictionary objects. We could use !dumpheap –mt &lt;methodtable&gt; to get a list of all the objects in that method table. Then used the address provided to use gcroot to give us all the paths to the object in our application.</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/mt1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="mt" border="0" alt="mt" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/mt_thumb1.png" width="454" height="70" /></a> </p>
<p>Notice in this case there is only one object and one memory address. If your method table or type has many addresses it could be difficult to identify or find your target object (in that case try to find the memory address through a parent object with less instances (or preferably, 1). If we use that address we can use the command “!gcroot 02369d30” to find all references the garbage collector knows is keeping the object down. Output will look something like this:</p>
<p><a href="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/gcroot1.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="gcroot" border="0" alt="gcroot" src="http://dandesousa.com/wordpress/wp-content/uploads/2010/08/gcroot_thumb1.png" width="454" height="242" /></a> </p>
<p>Work backwards from the bottom of each trace. It starts with the object in question and moves up the reference tree to a root node for the application. This would tell us that the object directly above our object is another dictionary, then a schema context and eventually a template. You can do this for any object you’d like to trace and see if the garbage collector will cleanup the object. </p>
<p>So whatever is holding onto our object could be causing the leak, therefore we could try to remove the link at the appropriate time, then re-observe to verify its status.</p>
<p>There are many functions available for SOS.dll. For a complete list of functions please visit the <a href="http://msdn.microsoft.com/en-us/library/bb190764(VS.80).aspx">MSDN site.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/28/finding-memory-leaks-in-net-using-sos-dll-and-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Infragistics WinForms Controls inside of WPF Applications</title>
		<link>http://dandesousa.com/2010/08/07/infragistics-winforms-controls-inside-of-wpf-applications/</link>
		<comments>http://dandesousa.com/2010/08/07/infragistics-winforms-controls-inside-of-wpf-applications/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 21:02:34 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=632</guid>
		<description><![CDATA[I recently tried to display a rather large amount of data in a WPF DataGrid control but found that it was rather slow. Particularly, when used with Data Binding (really the only way to display data from the grid). Response time was slow unless data was placed entirely asynchronously, which provides a delayed view of [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">I recently tried to display a rather large amount of data in a WPF DataGrid control but found that it was rather slow. Particularly, when used with Data Binding (really the only way to display data from the grid). Response time was slow unless data was placed entirely asynchronously, which provides a delayed view of the data that is neither attractive, nor necessary. So instead I used a WinForms control from a third party library and thus attempted to embed my first WinForms control in a WPF application.</p>
<p style="clear: both">WinForms objects are embeddable in WPF applications and vice versa. To do so, you simply create the appropriate &#8220;host&#8221;, then place the controls you want in the host as the child. If you want more than one, you can just create a container like a Panel and add any children as children to the Panel.</p>
<p style="clear: both"><strong>How To Embed WinForms in WPF</strong></p>
<p style="clear: both">First, you&#8217;ll need to add references to your project. In your WPF application you&#8217;ll need references to System.Windows.Forms. So check for it in the references under .NET. Additionally, if you are using a third party library like Infragistics for the controls you&#8217;ll need to <strong>right click on your project, select Properties, and verify that you are NOT using a Client Profile under your .NET framework version.</strong> Client Profiles are great for applications running only on local machines because they omit certain needless libraries pertaining to web code and servers. However, some third party libraries may link to those libraries and so you&#8217;ll need them in order to build your project. If you import the references for whatever third party controls but notice they are missing or namespaces won&#8217;t resolve, it&#8217;s because you are probably using the wrong .NET version or a Client Profile.</p>
<p style="clear: both">Once you are ready you can simply type the following:</p>
<pre class="brush: csharp;">
WindowsFormsHost host = new WindowsFormsHost();
host.child = someControl;
// Add the host object to whatever your page happens to be
myWindowGrid.Children.Add(host);
</pre>
<p>Hosting a WinForms control in WPF</p>
<p style="clear: both">You should then be able to access the WinForms control and have programmatic access to all its fields, properties and methods as though it were a WinForms application.</p>
<p style="clear: both"><strong>Some Caveats<br /></strong></p>
<p style="clear: both"><em>Namespace Conflicts</em></p>
<p style="clear: both">If you are trying to replace a WPF control with a WinForms control you should be aware of some gotchas. You will invariably run into namespace conflicts. When you hover the mouse over an object or method in VS2010 it will show you the return type of the object. Notice that many controls share a common name, however in WPF they are in System.Windows.Controls and in WinForms they are in System.Windows.Forms. Similarly, attributes and helpers in WPF tend to be in System.Media (like Colors, etc) but WinForms may be in System.Drawing. You&#8217;ll have to be explicit when talking about the type, especially since an event or attribute of a WPF control may not be compatible with a WinForms control (like Colors from styles and Points from MouseEvents).</p>
<p style="clear: both"><em>Marshaling Data on the UI</em></p>
<p style="clear: both">As you may or may not know, you cannot update an object on a different thread than the one it which it was created. This is true of both WPF and WinForms, but the method by which you perform this marshaling is different. In WPF you perform an operation like this:</p>
<p style="clear: both">
<pre class="brush: csharp;"> this.myObjects.Dispatcher.Invoke(myDelegateFunction, DispatcherPriority.Normal, myParams); </pre>
</p>
<p style="clear: both">where the delegate function signifies the operation that will modify myObject. This simply tells .NET to perform the operation on a compatible thread when it is able to. The Priority specifies how quickly this can be done. You can find details on which priorities to specify on Microsoft&#8217;s official page on the DispatcherPriority.</p>
<p style="clear: both">Now, the same function can be (and must be) performed in WinForms in a slightly different way.</p>
<p style="clear: both">
<pre class="brush: csharp;"> if(this.myUIControl.InvokeRequired) this.myUIControl.Invoke(myDelegateFunction, myParams); </pre>
</p>
<p style="clear: both">Keep this in mind as you create your app since this will cause crashes if not done correctly. Specifically in Infragistics UltraGrid, this results in random exceptions and a big red X after a couple of updates.</p>
<p style="clear: both">For more details and clarity on Marshaling data, <a href="http://weblogs.asp.net/justin_rogers/pages/126345.aspx">visit this page</a>, which provides an excellent overview on the subject.</p>
<p style="clear: both">
<p>  <br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/07/infragistics-winforms-controls-inside-of-wpf-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asynchronous Data Binding in .NET (C#)</title>
		<link>http://dandesousa.com/2010/08/07/asynchronous-data-binding-in-net-c/</link>
		<comments>http://dandesousa.com/2010/08/07/asynchronous-data-binding-in-net-c/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 20:31:54 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=630</guid>
		<description><![CDATA[Asynchronous operations are prevalent in all manner of modern systems, desktop and web applications. Doing this in .NET is relatively easy as Microsoft has provided us with a built in mechanism for binding data. Specifically in WPF, we can perform databinding simply by providing a binding target and a binding source. The binding target is [...]]]></description>
			<content:encoded><![CDATA[<p>Asynchronous operations are prevalent in all manner of modern systems, desktop and web applications. Doing this in .NET is relatively easy as Microsoft has provided us with a built in mechanism for binding data.</p>
<p>Specifically in WPF, we can perform databinding simply by providing a binding target and a binding source. The binding target is the object in which the data belongs and the source is the property which it will be placed (sort of backwards, but basically they refer to the two endpoints). I won&#8217;t write an entire article on Databinding but instead point you to<a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx"> MSDN&#8217;s official documentation on the subject</a>.</p>
<p>Needless to say Databinding is immensely powerful and greatly simplifies how we as developers deal with code in UI space. Now from the Microsoft example, assume we have a databinding code snippet that looks like this:</p>
<pre class="brush: csharp;">
 MyData myDataObject = new MyData(DateTime.Now);
  Binding myBinding = new Binding(&quot;MyDataProperty&quot;);
  myBinding.Source = myDataObject;
  myText.SetBinding(TextBlock.TextProperty, myBinding);
</pre>
<p>Then if we want to load the data asynchronously we would simply add:</p>
<pre class="brush: csharp;">
 MyData myDataObject = new MyData(DateTime.Now);
  Binding myBinding = new Binding(&quot;MyDataProperty&quot;);
  myBinding.Source = myDataObject;
  myText.SetBinding(TextBlock.TextProperty, myBinding);
// Load this asynchronously
myText.IsAsync = true;
</pre>
<p>Which tells the binding to not wait for the value but instead move on with any other work while it waits for the value to come in. If you want to display a placeholder value, we can set that as well.</p>
<pre class="brush: csharp;">
 MyData myDataObject = new MyData(DateTime.Now);
  Binding myBinding = new Binding(&quot;MyDataProperty&quot;);
  myBinding.Source = myDataObject;
  myText.SetBinding(TextBlock.TextProperty, myBinding);
// Load this asynchronously
myText.IsAsync = true;
myText.FallbackValue = &quot;Loading...&quot;
</pre>
<p>Which will initially display &#8220;Loading&#8230;&#8221; until the value is ready from the bound property. This is useful in situations where you want to load an image which may take a while but want to hold some placeholder image until it is ready (we see in many mobile applications where data loading may be unpredictable and slow).</p>
<p>If you want to load multiple levels of objects, you can create a PriorityBinding object which can contain multiple bindings as above, and set each individual Binding object to be asynchronous and it will load them in order as it gets them. You can find details about this on <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.prioritybinding.aspx">Microsoft&#8217;s PriorityBinding MSDN documentation page</a>.</p>
<p>Lastly, remember that just because a value is asynchronous does not mean it is automatically loaded from a different thread. If you want to ensure that the UI thread is not held up, whichever property you are bound to must have its data dispatched from another thread or launch a thread. This will ensure that retrieving the property will take slightly long and make the UI thread run smooth (user interactions will take precedent).</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/07/asynchronous-data-binding-in-net-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing XML in .NET C#</title>
		<link>http://dandesousa.com/2010/08/04/parsing-xml-in-net-c/</link>
		<comments>http://dandesousa.com/2010/08/04/parsing-xml-in-net-c/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 01:17:19 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=626</guid>
		<description><![CDATA[Parsing XML can be a painful, error prone process. In the System.Xml Namespace, .NET provides a number of tools for parsing XML. However, there is a slightly less known but easier way to automatically parse XML files. .NET has a tool called xsd.exe, which allows you to generate objects which can be used to automatically [...]]]></description>
			<content:encoded><![CDATA[<p>Parsing XML can be a painful, error prone process. In the System.Xml Namespace, .NET provides a number of tools for parsing XML. However, there is a slightly less known but easier way to automatically parse XML files. .NET has a tool called xsd.exe, which allows you to generate objects which can be used to automatically serialize and deserialize from an XML file. If you have the schema (.xsd) file or any xml file for the target you want to parse, this process is relatively easy. First you generate the proxy objects, then you deserialize the target file into the object to gain access to the XML contents in an object model.</p>
<p><strong>Generating XML Proxy Objects</strong></p>
<p>Open the VS2010 command prompt available via start-&gt;programs-&gt;visual studio 2010-&gt; vs2010 command prompt.</p>
<p>Navigate through the DOS prompt to the area containing your .xsd or .xml schema file</p>
<p>You simply run the command:</p>
<pre class="brush: csharp;">xsd schemafile.xsd /c</pre>
<p>This will create a .cs file contain all the necessary partial class definitions for deserializing any xml file conforming to the schema. Now you are ready to parse any XML file.</p>
<p><strong>Parsing XML through de-serialization</strong></p>
<p>Now you simply de-serialize the object like so:</p>
<pre class="brush: csharp;">
XmlReader r = new XmlReader(fileName);
// Set any XmlReader settings

ProxyObject o = new XmlSerializer(typeof(ProxyObject)).Deserialize(r) as ProxyObject;
</pre>
<p>Then all fields, tags, attributes are available in an object model where attributes are object fields and sub elements are arrays in parent objects (you can see the details in the generated .cs).</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/04/parsing-xml-in-net-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functional Programming in C#: Map / Select Function</title>
		<link>http://dandesousa.com/2010/08/02/functional-programming-in-c-map-select-function/</link>
		<comments>http://dandesousa.com/2010/08/02/functional-programming-in-c-map-select-function/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 01:29:11 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=611</guid>
		<description><![CDATA[C# has some particularly useful facilitates for functional programming built in. When operating on lists of data you can easily perform common functional programming tasks with built-in C# .NET functions, as long as the collection conforms to the IEnumerable interface. Consider the following example which performs the map command, which applies a function on every object in a collection [...]]]></description>
			<content:encoded><![CDATA[<p>C# has some particularly useful facilitates for functional programming built in. When operating on lists of data you can easily perform common functional programming tasks with built-in C# .NET functions, as long as the collection conforms to the IEnumerable interface.</p>
<p>Consider the following example which performs the map command, which applies a function on every object in a collection and returns a list with the result of each function call. This is accomplished in C# with the Select command.</p>
<pre class="brush: csharp;">
            IEnumerable&lt;double&gt; myList = new List&lt;double&gt;();
            // Populate the list ...

            // Fills the list with the sqrt of all the values in myList
            IEnumerable&lt;double&gt; sqrtList = myList.Select&lt;double, double&gt;(Math.Sqrt);
</pre>
<p>You can use this as a short cut way of applying an operation on all the elements in a list. Of course you could do this in a slightly longer way by just iterating over all the elements in the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/08/02/functional-programming-in-c-map-select-function/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft Solver Foundation for Quadratic Programming</title>
		<link>http://dandesousa.com/2010/07/15/microsoft-solver-foundation-for-quadratic-programming/</link>
		<comments>http://dandesousa.com/2010/07/15/microsoft-solver-foundation-for-quadratic-programming/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 01:55:13 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=582</guid>
		<description><![CDATA[The Microsoft Solver Foundation provides some excellent APIs for solving optimization problems in C# .NET. Getting to documentation about the Quadratic Programming facilities can be a bit tricky though. I&#8217;ve added below some sample code to help out with this. In the following example I&#8217;m solving an example of the lagrangian dual form used for [...]]]></description>
			<content:encoded><![CDATA[<p>The Microsoft Solver Foundation provides some excellent APIs for solving optimization problems in C# .NET. Getting to documentation about the Quadratic Programming facilities can be a bit tricky though. I&#8217;ve added below some sample code to help out with this.</p>
<p>In the following example I&#8217;m solving an example of the lagrangian dual form used for classification in an SVM.</p>
<pre class="brush: csharp;">// Classify using solver
InteriorPointSolver solver = new InteriorPointSolver();

// Langrangian Dual
int dual = 0;
solver.AddRow(&quot;L&quot;, out dual);

// Sum Constraint
int linearConstraint = 0;
solver.AddRow(&quot;SumConstraint&quot;, out linearConstraint);

// Add variables and Lagrangian linear terms
int[] vars = new int[n];
for (int i = 0; i &amp;lt; n; i++)
{
	// Add the variable
	solver.AddVariable(&quot;a&quot; + i, out vars[i]);

	// Factor in C upper bounds
	solver.SetBounds(vars[i], 0, C);
}

// Linear constraint must equal 0
solver.SetBounds(linearConstraint, 0, 0);

// Lagrangian Quadratic Terms
for (int i = 0; i &amp;lt; n; i++) { 	solver.SetCoefficient(linearConstraint, vars[i], trainingData[i].output()); 	solver.SetCoefficient(dual, vars[i], 1); 	Parallel.For(0, n, o, (int j) =&amp;gt;
	{
		double coef = trainingData[i].output() * trainingData[j].output() *
			kernel.evaluate(trainingData[i].point(), trainingData[j].point());

		solver.SetCoefficient(dual, -0.5 * coef, vars[i], vars[j]);
	});
}

solver.AddGoal(dual, 0, false);

InteriorPointSolverParams param = new InteriorPointSolverParams();</pre>
<p>Essentially all we are doing here is adding all the variables to our constraint optimization problem and asking the solver to minimize. The vars array simply expressing a list of identifier for variables in the constraint problem. You should fire up the Solver Foundation library and give it a shot yourself.</p>
<p>Here are some resources that should make understanding this a bit easier as well. Its the official blog of one of the key developers on the project, specifically the links to tutorial on the quadratic programming solver.</p>
<p style="text-align: center;"><a href="http://blogs.msdn.com/b/natbr/archive/2009/09/24/using-the-solver-foundation-interior-point-solver.aspx">Nathan Brixius&#8217; QP Solver Tutorial</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/07/15/microsoft-solver-foundation-for-quadratic-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ChessGL3d Demo Video</title>
		<link>http://dandesousa.com/2010/03/11/chessgl3d/</link>
		<comments>http://dandesousa.com/2010/03/11/chessgl3d/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 19:29:37 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[opengl]]></category>

		<guid isPermaLink="false">http://dandesousa.com/2010/03/11/chessgl3d/</guid>
		<description><![CDATA[chessgl3d, originally uploaded by dandesousa. Here is a demo video for my 3d chess game. See the games page for more details.]]></description>
			<content:encoded><![CDATA[<div style="text-align: left; padding: 3px;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="313" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="data" value="http://www.flickr.com/apps/video/stewart.swf?v=71377" /><param name="flashvars" value="intl_lang=en-us&amp;photo_secret=6ee39f773e&amp;photo_id=4425552860&amp;flickr_show_info_box=true" /><param name="bgcolor" value="#000000" /><param name="allowFullScreen" value="true" /><param name="src" value="http://www.flickr.com/apps/video/stewart.swf?v=71377" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="500" height="313" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" allowfullscreen="true" bgcolor="#000000" flashvars="intl_lang=en-us&amp;photo_secret=6ee39f773e&amp;photo_id=4425552860&amp;flickr_show_info_box=true" data="http://www.flickr.com/apps/video/stewart.swf?v=71377"></embed></object></p>
<p><span style="font-size: 0.8em; margin-top: 0px;"><a href="http://www.flickr.com/photos/dandesousa/4425552860/">chessgl3d</a>, originally uploaded by <a href="http://www.flickr.com/people/dandesousa/">dandesousa</a>.</span></div>
<p class="flickr-yourcomment">Here is a demo video for my 3d chess game. See the games page for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/03/11/chessgl3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL Display Lists And Sub Windows</title>
		<link>http://dandesousa.com/2010/03/06/opengl-display-lists-and-sub-windows/</link>
		<comments>http://dandesousa.com/2010/03/06/opengl-display-lists-and-sub-windows/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 02:02:08 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[opengl]]></category>

		<guid isPermaLink="false">http://dandesousa.com/?p=522</guid>
		<description><![CDATA[I recently discovered after some needless frustration, that you need to declare display lists that contain model drawing information in all windows in which you wish to draw the model. For example, if I say: glutSetWindow(main_window); initDisplayLists(); ... void main_display() { drawDisplayList(); } It will work just fine. But if I try to do the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered after some needless frustration, that you need to declare display lists that contain model drawing information in all windows in which you wish to draw the model. For example, if I say:</p>
<pre>glutSetWindow(main_window);
initDisplayLists();
...
void main_display()
{
   drawDisplayList();
}</pre>
<p>It will work just fine. But if I try to do the same in a display function of the sub window it won&#8217;t draw. You need to call whatever init() function you create your models / display lists in AFTER setting the window. For example</p>
<pre>
glutSetWindow(main_window);
// do stuff

glutSetWindow(sub_window);
initDisplayLists();
...

void sub_display()
{
    drawDisplayList();
}
</pre>
<p>Hope that helps someone out there!</p>
]]></content:encoded>
			<wfw:commentRss>http://dandesousa.com/2010/03/06/opengl-display-lists-and-sub-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
