<?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>17 of 26 &#187; WPF</title>
	<atom:link href="http://17of26.com/category/programming/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://17of26.com</link>
	<description>the world of programming and technology</description>
	<lastBuildDate>Fri, 11 Dec 2009 01:29:05 +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>Learning C# and WPF</title>
		<link>http://17of26.com/2009/09/learning-csharp-wpf/</link>
		<comments>http://17of26.com/2009/09/learning-csharp-wpf/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 04:29:40 +0000</pubDate>
		<dc:creator>Q</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://17of26.com/?p=360</guid>
		<description><![CDATA[A while back, I decided that I was going to use C# and Windows Presentation Foundation (WPF) to implement any Windows desktop applications that I write.  I had some exposure to both technologies at my last job and want to learn more of them.  I liked what I saw of the C# language and I [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, I decided that I was going to use <a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29">C#</a> and <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation">Windows Presentation Foundation (WPF)</a> to implement any Windows desktop applications that I write.  I had some exposure to both technologies at my last job and want to learn more of them.  I liked what I saw of the C# language and I think that WPF is a fantastic platform for developing user interfaces.</p>
<p>When coming up to speed on new programming technologies, I really prefer using books to get started rather than searching online.  Books are great for a couple of reasons:</p>
<p>1) A solid chunk of information in one spot rather than having to piece together bits scattered all over the internet. A book is also usually presented in a logical order with the early chapters being basic fundamentals and subsequent chapters building on that.</p>
<p>2) A book has been reviewed and edited so that the information in it is almost always accurate (although sometimes a bit out of date). When you find a random article through Google you really have no idea if the information presented is accurate in any way. And even worse, the information you find is often not dated so you don&#8217;t even know if it&#8217;s recent.</p>
<p>Google is your best friend when trying to find an answer to a specific question, but it&#8217;s really hard to to know what questions to ask when you are unfamiliar with the topic at hand.</p>
<p>I&#8217;ve been using the following books to learn C#/WPF:</p>
<div>
<div style="float:left; margin-right:10px;">
<a href="http://www.amazon.com/gp/product/0764575341?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0764575341"><img border="0" src="/img/amazon/51RHqu22ldL._SL160_.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=0764575341" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<h3 style="margin-bottom:10px"><a href="http://www.amazon.com/gp/product/0764575341?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0764575341">Professional C# 2005</a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=0764575341" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h3>
<p>I got this book a few years ago and it&#8217;s decent as an introduction to the C# language.  It goes over all of the C# syntax and language features &#8211; it&#8217;s not bad, but not great either.  The major downside is that it only covers version 2.0 of the language (3.0 has been out for a while, and 4.0 is on the way).  There is an updated version, <a href="http://www.amazon.com/gp/product/0470191376?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0470191376">Professional C# 2008</a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=0470191376" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />, which covers C# 3.0.</div>
<div style="clear:both; margin-top:10px;">
<div style="float:left; margin-right:10px;"><a href="http://www.amazon.com/gp/product/1933988363?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1933988363"><img border="0" src="/img/amazon/41-I8sBZWSL._SL160_.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=1933988363" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<h3 style="margin-bottom:10px"><a href="http://www.amazon.com/gp/product/1933988363?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1933988363">C# in Depth: What you need to master C# 2 and 3</a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=1933988363" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</h3>
<p>I’m still working my way through this book, but so far it’s fantastic. The book focuses on detailed explanations of the advanced features that were added in C# 2.0 and 3.0. If you want to really understand of inner workings of the C# language – this book is for you. Due to the advanced topics that it covers, the book assumes that you already know the basics of C#.
</p></div>
<div style="clear:both; margin-top:10px;">
<div style="float:left; margin-right:10px;"><a href="http://www.amazon.com/gp/product/1933988223?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1933988223"><img border="0" src="/img/amazon/51M%2B4h9xIrL._SL160_.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=1933988223" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<h3 style="margin-bottom:10px"><a href="http://www.amazon.com/gp/product/1933988223?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1933988223">WPF in Action with Visual Studio 2008</a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=1933988223" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</h3>
<p>This book starts off with talking about the history of UI development, covering both Windows drawing and web UI design.  It outlines the flaws in these previous approaches to UI development and explains the technical design goals of WPF.  It&#8217;s interesting background information and I found it helpful to know the motivations behind the design of WPF.  The rest of the book covers a set of carefully selected topics in great detail.  It&#8217;s by no means a comprehensive reference for WPF, but what the book does cover it covers very well.  There&#8217;s a lot of &#8220;how&#8221; and &#8220;why&#8221; explained so that you get a full understanding of each topic.  The book is written with a good sense of humor so it&#8217;s very easy to read.  As of this writing, it&#8217;s also the most recent WPF book published and covers .NET 3.5 SP1.
</p></div>
<div style="clear:both; margin-top:10px;">
<div style="float:left; margin-right:10px;"><a href="http://www.amazon.com/gp/product/0596510373?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596510373"><img border="0" src="/img/amazon/41nklsJ3o5L._SL160_.jpg"></a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=0596510373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</div>
<h3 style="margin-bottom:10px"><a href="http://www.amazon.com/gp/product/0596510373?ie=UTF8&#038;tag=17of26-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596510373">Programming WPF</a><img src="http://www.assoc-amazon.com/e/ir?t=17of26-20&#038;l=as2&#038;o=1&#038;a=0596510373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</h3>
<p>This book is big (863 pages) and covers a wide range of WPF topics with a good amount of detail.  Like WPF In Action, the writing style is excellent and the authors make the material relatively easy to understand.  Its topic coverage is a little different than WPF In Action (with some overlap, obviously) so the two books complement each other well.
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://17of26.com/2009/09/learning-csharp-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Host WPF Content in MFC Applications</title>
		<link>http://17of26.com/2009/07/how-to-host-wpf-content-in-mfc-applications/</link>
		<comments>http://17of26.com/2009/07/how-to-host-wpf-content-in-mfc-applications/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 03:12:53 +0000</pubDate>
		<dc:creator>Q</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://17of26.com/?p=300</guid>
		<description><![CDATA[This is something that I figured out a while back but wanted write about it here since I spent a few hours piecing together the information.
There is an MSDN Walkthrough that gets you most of the way there, but there are a couple of key pieces that I found elsewhere. For example, the walkthrough tells [...]]]></description>
			<content:encoded><![CDATA[<p>This is something that I figured out a while back but wanted write about it here since I spent a few hours piecing together the information.</p>
<p>There is an <a rel="nofollow" href="http://msdn.microsoft.com/en-us/library/ms744829.aspx">MSDN Walkthrough</a> that gets you most of the way there, but there are a couple of key pieces that I found elsewhere. For example, the walkthrough tells you to place the line [System::STAThreadAttribute] before the _tWinMain() definition but if you&#8217;re implementing a standard MFC application then you don&#8217;t have _tWinMain() in your source code.</p>
<h4><strong>Step 1: Configure the MFC application to compile with CLR support</strong></h4>
<p>The best way to achieve interoperability between native C++ and managed .NET code is to compile the application as managed C++ rather than native C++. This is done by going to the Configuration Properties of the project. Under General there is an option &#8220;Common Language Runtime support&#8221;. Set this to &#8220;Common Language Runtime Support /clr&#8221;.</p>
<h4><strong>Step 2: Add the WPF assemblies to the project</strong></h4>
<p>Right-click on the project in the Solution Explorer and choose &#8220;References&#8221;. Click &#8220;Add New Reference&#8221;. Under the .NET tab, add WindowsBase, PresentationCore, PresentationFramework, and System. Make sure you Rebuild All after adding any references in order for them to get picked up.</p>
<h4>Step 3: Set STAThreadAttribute on the MFC application</h4>
<p>WPF requires that STAThreadAttribute be set on the main UI thread. Set this by going to Configuration Properties of the project. Under Linker-&gt;Advanced there is an option called &#8220;CLR Thread Attribute&#8221;. Set this to &#8220;STA threading attribute&#8221;.</p>
<h4><strong>Step 4: Create an instance of HwndSource to wrap the WPF component</strong></h4>
<p>System::Windows::Interop::HwndSource is a .NET class that handles the interaction between MFC and .NET components. Create one using the following syntax:</p>
<pre class="syntax-highlight:c++">System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew     System::Windows::Interop::HwndSourceParameters(&quot;MyWindowName&quot;);
sourceParams-&gt;PositionX = x;
sourceParams-&gt;PositionY = y;
sourceParams-&gt;ParentWindow = System::IntPtr(hWndParent);
sourceParams-&gt;WindowStyle = WS_VISIBLE | WS_CHILD;

System::Windows::Interop::HwndSource^ source = gcnew System::Windows::Interop::HwndSource(*sourceParams);
source-&gt;SizeToContent = System::Windows::SizeToContent::WidthAndHeight;</pre>
<p>Add an HWND member variable to the dialog class and then assign it like this: m_hWnd = (HWND) source-&gt;Handle.ToPointer();  The source object and the associated WPF content will remain in existence until you call ::DestroyWindow(m_hWnd).</p>
<h4><strong>Step 5: Add the WPF control to the HwndSource wrapper</strong></h4>
<pre><strong>
<pre class="syntax-highlight:c++">&lt;/strong&gt;System::Windows::Controls::WebBrowser^ browser = gcnew System::Windows::Controls::WebBrowser();

browser-&gt;Height = height;
browser-&gt;Width = width;
source-&gt;RootVisual = browser;&lt;strong&gt;</pre>
<p></strong></pre>
<h4>Step 6: Keep a reference to the WPF object</h4>
<p>Since the browser variable will go out of scope after we exit the function doing the creation, we need to somehow hold a reference to it. Managed objects cannot be members of unmanaged objects but you can use a wrapper template called gcroot to get the job done.</p>
<p>Add a member variable to the dialog class:</p>
<pre></pre>
<pre class="syntax-highlight:c++">&lt;span&gt;#include &lt;vcclr.h&gt;&lt;/span&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;gcroot&lt;/span&gt;&lt;span&gt;&lt;&lt;/span&gt;&lt;span&gt;System&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span&gt;Windows&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span&gt;Controls&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span&gt;WebBrowser&lt;/span&gt;&lt;span&gt;^&gt;&lt;/span&gt;&lt;span&gt; m_webBrowser&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/code&gt;</pre>
</pre>
<p>Then add the following line to the code in Step 5:</p>
<pre class="syntax-highlight:c++">&lt;code&gt;&lt;span&gt;m_webBrowser &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; browser&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/code&gt;</pre>
<p>Now you can access properties and methods on the WPF component through m_webBrowser.</p>
]]></content:encoded>
			<wfw:commentRss>http://17of26.com/2009/07/how-to-host-wpf-content-in-mfc-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
