<?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>Ticklish Techs &#187; wpf</title>
	<atom:link href="http://www.ticklishtechs.net/tag/wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Wed, 05 Jan 2011 21:44:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>A Change event for Dependency Properties</title>
		<link>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/</link>
		<comments>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 11:38:16 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dotnet3.5]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/</guid>
		<description><![CDATA[WPF comes with Dependency Properties and everybody using WPF will know about these new kind of properties. When you define your own Dependency Properties in your own class you can pretty easy add a property change event handler: public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } public static [...]]]></description>
			<content:encoded><![CDATA[<p>WPF comes with Dependency Properties and everybody using WPF will know about these new kind of properties. When you define your own Dependency Properties in your own class you can pretty easy add a property change event handler:</p>
<pre class="code"><span style="color: blue;">public int </span>MyProperty
{
    <span style="color: blue;">get </span>{ <span style="color: blue;">return </span>(<span style="color: blue;">int</span>)GetValue(MyPropertyProperty); }
    <span style="color: blue;">set </span>{ SetValue(MyPropertyProperty, <span style="color: blue;">value</span>); }
}
<span style="color: blue;">public static readonly </span><span style="color: #2b91af;">DependencyProperty </span>MyPropertyProperty =
    <span style="color: #2b91af;">DependencyProperty</span>.Register(<span style="color: #a31515;">"MyProperty"</span>,
                        <span style="color: blue;">typeof</span>(<span style="color: blue;">int</span>),
                        <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">MainWindow</span>),
                        <span style="color: blue;">new </span><span style="color: #2b91af;">UIPropertyMetadata</span>(0,
                            <strong>MyPropertyvalueChangeCallback</strong>));

<span style="color: blue;">private static void </span><strong>MyPropertyvalueChangeCallback</strong>
                        (<span style="color: #2b91af;">DependencyObject </span>d,
                         <span style="color: #2b91af;">DependencyPropertyChangedEventArgs </span>e)
{
}</pre>
<p>But how to add such a event handler to an already existing Dependency Property or somewhere else then in the defining class? E.g. to an property of a WPF-Control that was not build by you. Take a standard WPF-TextBox; both the <code>Text</code> and the <code>FontSize</code> properties are Dependency Properties but the <code>TextBox</code>-class only provides a change event for the <code>Text</code>-property. Nevertheless you can get a change event for any Dependency Property:</p>
<pre class="code"><span style="color: #2b91af;">DependencyPropertyDescriptor </span>dpd =
    <span style="color: #2b91af;">DependencyPropertyDescriptor</span>.FromProperty
        (<span style="color: #2b91af;">Control</span>.FontSizeProperty, <span style="color: blue;">typeof </span>(<span style="color: #2b91af;">TextBox</span>));
dpd.AddValueChanged(someTextBox, SomeTextBoxFontSizeChanged);</pre>
<p>Every time the FontSizeProperty on the instance <code>someTextBox</code> changes the given method is called. It’s that easy and you can implement this code everywhere not only within the class that defines the property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2010/02/15/a-change-event-for-dependency-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get a IWin32Window from a WPF Window?</title>
		<link>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/</link>
		<comments>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 12:53:34 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/</guid>
		<description><![CDATA[When building applications that mix WPF and Winforms windows (e.g. because you are using a Winforms dialog within a WPF application) you will sometimes need a System.Windows.Forms.IWin32Window interface from an WPF System.Windows.Window. This will be useful when using the WinForms OpenFileDialog and wanting to provide a parent window to the ShowDialog() method that only accepts [...]]]></description>
			<content:encoded><![CDATA[<p>When building applications that mix WPF and Winforms windows (e.g. because you are using a Winforms dialog within a WPF application) you will sometimes need a <a title="IWin32Window Interface" href="http://msdn2.microsoft.com/215475ec.aspx">System.Windows.Forms.IWin32Window</a> interface from an WPF <a title="Window Class" href="http://msdn2.microsoft.com/ms590112.aspx">System.Windows.Window</a>. This will be useful when using the WinForms <a title="OpenFileDialog Class" href="http://msdn2.microsoft.com/y1kh29w3.aspx">OpenFileDialog</a> and wanting to provide a parent window to the <a title="OpenFileDialog..::.ShowDialog Method " href="http://msdn2.microsoft.com/bb552427.aspx">ShowDialog()</a> method that only accepts IWin32Window as parent.</p>
<p>The <code>IWin32Window</code> interface declares only one read-only property named <code>Handle</code> that must be provided by the WPF Window. </p>
<h3>Implementing the Interface</h3>
<p>It is very simple to just add this interface to an existing WPF Window and implementing the single property:</p>
<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Window1 </span>: <span style="color: #2b91af">Window</span>, <span style="color: #2b91af">IWin32Window
</span>{
   <span style="color: blue">public </span><span style="color: #2b91af">IntPtr </span>Handle
   {
      <span style="color: blue">get
      </span>{
         <span style="color: blue">var </span>interopHelper = <span style="color: blue">new </span><span style="color: #2b91af">WindowInteropHelper</span>(<span style="color: blue">this</span>);
         <span style="color: blue">return </span>interopHelper.Handle;
      }
   }
}</pre>
<p>&#160;</p>
<h3>Using a wrapper class</h3>
<p>It does not look as a very good solution to add such an interface to each and every <code>Window</code> in you whole application only to be able to be the parent of a dialog. So instead of implementing the interface directly you could build a wrapper class that implements this interface and use this wrapper when opening a dialog:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">Wpf32Window </span>: <span style="color: #2b91af">IWin32Window
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">IntPtr </span>Handle { <span style="color: blue">get</span>; <span style="color: blue">private set</span>; }

    <span style="color: blue">public </span>Wpf32Window(<span style="color: #2b91af">Window </span>wpfWindow)
    {
        Handle = <span style="color: blue">new </span><span style="color: #2b91af">WindowInteropHelper</span>(wpfWindow).Handle;
    }
}</pre>
<p>Opening the dialog will now look like: </p>
<pre class="code">d.ShowDialog( <span style="color: blue">new </span><span style="color: #2b91af">Wpf32Window</span>(<span style="color: blue">this</span>) );</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h3>The grand solution to this problem</h3>
<p>I like the wrapper solution more than implementing an interface to each and every window but I do not like the changed <code>ShowDialog()</code> call. It just does not look natural any more. To solve this I created an extension Method to be used with the wrapper class:</p>
<pre class="code"><span style="color: blue">public static class </span><span style="color: #2b91af">CommonDialogExtensions
</span>{
    <span style="color: blue">public static </span><span style="color: #2b91af">DialogResult </span>ShowDialog
                               (<span style="color: blue">this </span><span style="color: #2b91af">CommonDialog </span>dialog,
                                     <span style="color: #2b91af">Window </span>parent)
    {
        <span style="color: blue">return </span>dialog.ShowDialog(<span style="color: blue">new </span><span style="color: #2b91af">Wpf32Window</span>(parent));
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Now the call to open a WinForms dialog with an WPF parent looks as it should look like:</p>
<pre class="code">d.ShowDialog(<span style="color: blue">this</span>);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Isn&#8217;t one OpenFileDialog enough?</title>
		<link>http://www.ticklishtechs.net/2009/12/22/isnt-one-openfiledialog-enough/</link>
		<comments>http://www.ticklishtechs.net/2009/12/22/isnt-one-openfiledialog-enough/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 12:53:25 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/12/22/isnt-one-openfiledialog-enough/</guid>
		<description><![CDATA[In fact one OpenFileDialog is enough but the .net framework provides two of them: System.Windows.Forms.OpenFileDialog in System.Windows.Forms.dll Microsoft.Win32.OpenFileDialog in PresentationFramework.dll (that is WPF) With such a setup one would use the first for WinForms applications and the second for WPF apps. In fact if you create a WPF application and just type in OpenFileDialog you [...]]]></description>
			<content:encoded><![CDATA[<p>In fact one OpenFileDialog is enough but the .net framework provides two of them:</p>
<ol>
<li><a title="OpenFileDialog Class" href="http://msdn2.microsoft.com/y1kh29w3.aspx">System.Windows.Forms.OpenFileDialog</a> in System.Windows.Forms.dll </li>
<li><a title="OpenFileDialog Class" href="http://msdn2.microsoft.com/ms653561.aspx">Microsoft.Win32.OpenFileDialog</a> in PresentationFramework.dll (that is WPF) </li>
</ol>
<p>With such a setup one would use the first for WinForms applications and the second for WPF apps. In fact if you create a WPF application and just type in <code>OpenFileDialog</code> you will get number 2.</p>
<p>But the 2nd one (even if it is part of the newer part of the framework) is an old dialog where the 1st will use the new and shiny Windows 7 dialog on Win7. Just look at the following screenshots.</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/12/a.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="a" border="0" alt="a" src="http://www.ticklishtechs.net/wp-content/uploads/2009/12/a_thumb.png" width="404" height="337" /></a> </p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/12/b.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="b" border="0" alt="b" src="http://www.ticklishtechs.net/wp-content/uploads/2009/12/b_thumb.png" width="404" height="301" /></a> </p>
<p>Only the first class uses the Windows 7 dialog and comes with proper support for Libraries etc. Even if the second shows the Libraries in its left part it does not fully support this new Windows 7 feature.</p>
<p>I have no idea why the WPF class uses the old windows API but it does. For best compatibility with all Windows versions (including 7) you should always use the Winforms Dialog even when building WPF apps! It does not hurt to reference the System.Windows.Forms.dll (it is installed an every machine running the .net framework) and you can use that dialog from WPF without any trouble.</p>
<p>You should only know about one little disadvantage when using the WinForms dialog. It only accepts WinForms as a parent window no WPF windows. To overcome this limitation please read my other article about the <code>IWin32Window</code> interface and how to implement / provide it in WPF at <a title="http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/" href="http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/">http://www.ticklishtechs.net/2009/12/22/how-to-get-a-iwin32window-from-a-wpf-window/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/12/22/isnt-one-openfiledialog-enough/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

