<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Martin's 10</title>
	<atom:link href="http://wangmo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wangmo.wordpress.com</link>
	<description>A little bit Serious</description>
	<lastBuildDate>Sat, 14 Jan 2012 12:51:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='wangmo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Martin's 10</title>
		<link>http://wangmo.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://wangmo.wordpress.com/osd.xml" title="Martin&#039;s 10" />
	<atom:link rel='hub' href='http://wangmo.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Create a custom Main method for WPF application</title>
		<link>http://wangmo.wordpress.com/2009/01/08/create-a-custom-main-method-for-wpf-application/</link>
		<comments>http://wangmo.wordpress.com/2009/01/08/create-a-custom-main-method-for-wpf-application/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 10:31:48 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[C# codes]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=120</guid>
		<description><![CDATA[When you create a new WPF Project the project template will create an App.xaml for you. Since WPF does a little magic behind the scenes, there is no way to access the Main method of your application. In this case, you simply delete the App.xaml and create a new App.cs class with the following code: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=120&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you create a new WPF Project the project template will create an App.xaml for you. Since WPF does a little magic behind the scenes, there is no way to access the Main method of your application. In this case, you simply delete the App.xaml and create a new App.cs class with the following code:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">App </span>: System.Windows.<span style="color:#2b91af;">Application
    </span>{
        <span style="color:blue;">public </span>Application()
        {
            StartupUri = <span style="color:blue;">new </span><span style="color:#2b91af;">Uri</span>(<span style="color:#a31515;">"Window1.xaml"</span>, <span style="color:#2b91af;">UriKind</span>.Relative);
        }

        [System.<span style="color:#2b91af;">STAThreadAttribute</span>()]
        [System.Diagnostics.<span style="color:#2b91af;">DebuggerNonUserCodeAttribute</span>()]
        <strong>[System.<span style="color:#2b91af;">LoaderOptimization</span>(<span style="color:#2b91af;">LoaderOptimization</span>.MultiDomainHost)]</strong>
        <span style="color:blue;">public static void </span>Main()
        {
            <span style="color:#2b91af;">Application </span>app = <span style="color:blue;">new </span><span style="color:#2b91af;">Application</span>();
            EnsureApplicationResources();
            app.Run();
        }
<span class="Normal">
<span style="font-family:Courier New;"><span style="color:blue;">private </span><span style="color:blue;">static</span> <span style="color:blue;">void</span> EnsureApplicationResources()
</span>{<span style="font-family:Courier New;">

</span><span style="font-family:Courier New;">        <span style="color:green;">// merge in your application resources

</span></span><span style="font-family:Courier New;">        <span style="color:#2b91af;">Application</span>.Current.Resources.MergedDictionaries.Add(

</span><span style="font-family:Courier New;">            <span style="color:#2b91af;">Application</span>.LoadComponent(

</span><span style="font-family:Courier New;">                <span style="color:blue;">new</span> <span style="color:#2b91af;">Uri</span>(<span style="color:#a31515;">"CustomAppTest;component/Resources/App.xaml"</span>,

</span><span style="font-family:Courier New;">                <span style="color:#2b91af;">UriKind</span>.Relative)) <span style="color:blue;">as</span> <span style="color:#2b91af;">ResourceDictionary</span>);

</span><span style="font-family:Courier New;">    }

</span><span style="font-family:Courier New;">}</span>
</span>
    }</pre>
<p>http://blog.matthidinger.com/2008/10/12/Increase+AddIn+Performance+With+MAF+And+WPF+Using+LoaderOptimization.aspx</p>
<p>http://www.drwpf.com/blog/Home/tabid/36/EntryID/10/Default.aspx</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=120&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2009/01/08/create-a-custom-main-method-for-wpf-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use OpacityMask to make UIElement partly invisible</title>
		<link>http://wangmo.wordpress.com/2008/12/16/how-to-use-opacitymask-to-make-uielement-partly-invisible/</link>
		<comments>http://wangmo.wordpress.com/2008/12/16/how-to-use-opacitymask-to-make-uielement-partly-invisible/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 22:51:47 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[OpacityMask]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=115</guid>
		<description><![CDATA[&#60;Button HorizontalAlignment=&#8221;Stretch&#8221; VerticalAlignment=&#8221;Stretch&#8221; Content=&#8221;Button&#8221;&#62; &#60;Button.OpacityMask&#62; &#60;LinearGradientBrush EndPoint=&#8221;0.5,1&#8243; StartPoint=&#8221;0.5,0&#8243;&#62; &#60;GradientStop Color=&#8221;#FF000000&#8243; Offset=&#8221;0&#8243;/&#62; &#60;GradientStop Color=&#8221;#FF000000&#8243; Offset=&#8221;0.5&#8243;/&#62; &#60;GradientStop Color=&#8221;#00000000&#8243; Offset=&#8221;0.5&#8243;/&#62; &#60;/LinearGradientBrush&#62; &#60;/Button.OpacityMask&#62; &#60;/Button&#62;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=115&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&lt;Button HorizontalAlignment=&#8221;Stretch&#8221; VerticalAlignment=&#8221;Stretch&#8221; Content=&#8221;Button&#8221;&gt;<br />
&lt;Button.OpacityMask&gt;<br />
&lt;LinearGradientBrush EndPoint=&#8221;0.5,1&#8243; StartPoint=&#8221;0.5,0&#8243;&gt;<br />
&lt;GradientStop Color=&#8221;#FF000000&#8243; Offset=&#8221;0&#8243;/&gt;<br />
&lt;GradientStop Color=&#8221;#FF000000&#8243; Offset=&#8221;0.5&#8243;/&gt;<br />
&lt;GradientStop Color=&#8221;#00000000&#8243; Offset=&#8221;0.5&#8243;/&gt;<br />
&lt;/LinearGradientBrush&gt;<br />
&lt;/Button.OpacityMask&gt;<br />
&lt;/Button&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=115&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/12/16/how-to-use-opacitymask-to-make-uielement-partly-invisible/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>xml:lang in XAML</title>
		<link>http://wangmo.wordpress.com/2008/12/13/xmllang-in-xaml/</link>
		<comments>http://wangmo.wordpress.com/2008/12/13/xmllang-in-xaml/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 00:17:23 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[localization]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=113</guid>
		<description><![CDATA[XAML xml:lang property Notice the xml:lang placed at the root element of the XAML file. This property describes the culture of a given element and its children. This value is used by several features in WPF and should be changed appropriately during localization. This value changes what language dictionary is use to hyphenate and spell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=113&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3 class="title4">XAML xml:lang property</h3>
<p>Notice the xml:lang placed at the root element of the XAML file. This property describes the culture of a given element and its children. This value is used by several features in WPF and should be changed appropriately during localization. This value changes what language dictionary is use to hyphenate and spell check words. It also affects the display of digits and how the font fallback system selects which font to use. Finally, the property affects the way numbers are displayed and the way texts written in complex scripts are shaped. The default value is “en-US”.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=113&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/12/13/xmllang-in-xaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>Pitfall with using triggers in Style and ControlTemplate</title>
		<link>http://wangmo.wordpress.com/2008/12/12/pitfall-with-using-triggers-in-style-and-controltemplate/</link>
		<comments>http://wangmo.wordpress.com/2008/12/12/pitfall-with-using-triggers-in-style-and-controltemplate/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 02:21:45 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[datatrigger]]></category>
		<category><![CDATA[dependencyproperty]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=111</guid>
		<description><![CDATA[Using triggers, including datatriggers, in Style and ControlTemplate can be sometimes tricky. Check out the following two code snippets. &#60;Grid Background=&#8221;Red&#8221;&#62; &#60;Grid.Style&#62; &#60;Style TargetType=&#8221;{x:Type Grid}&#8221;&#62; &#60;Style.Triggers&#62; &#60;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&#62; &#60;Setter Property=&#8221;Background&#8221; Value=&#8221;Green&#8221;/&#62; &#60;/Trigger&#62; &#60;/Style.Triggers&#62; &#60;/Style&#62; &#60;/Grid.Style&#62; &#60;/Grid&#62; &#60;Button Content=&#8221;Test&#8221; Foreground=&#8221;Red&#8221;&#62; &#60;Button.Template&#62; &#60;ControlTemplate TargetType=&#8221;{x:Type Button}&#8221;&#62; &#60;Grid&#62; &#60;ContentPresenter/&#62; &#60;/Grid&#62; &#60;ControlTemplate.Triggers&#62; &#60;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&#62; &#60;Setter Property=&#8221;Foreground&#8221; Value=&#8221;Green&#8221;/&#62; &#60;/Trigger&#62; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=111&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using triggers, including datatriggers, in Style and ControlTemplate can be sometimes tricky. Check out the following two code snippets.</p>
<p>&lt;Grid Background=&#8221;Red&#8221;&gt;<br />
&lt;Grid.Style&gt;<br />
&lt;Style TargetType=&#8221;{x:Type Grid}&#8221;&gt;<br />
&lt;Style.Triggers&gt;<br />
&lt;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&gt;<br />
&lt;Setter Property=&#8221;Background&#8221; Value=&#8221;Green&#8221;/&gt;<br />
&lt;/Trigger&gt;<br />
&lt;/Style.Triggers&gt;<br />
&lt;/Style&gt;<br />
&lt;/Grid.Style&gt;<br />
&lt;/Grid&gt;</p>
<p>&lt;Button Content=&#8221;Test&#8221; Foreground=&#8221;Red&#8221;&gt;<br />
&lt;Button.Template&gt;<br />
&lt;ControlTemplate TargetType=&#8221;{x:Type Button}&#8221;&gt;<br />
&lt;Grid&gt;<br />
&lt;ContentPresenter/&gt;<br />
&lt;/Grid&gt;<br />
&lt;ControlTemplate.Triggers&gt;<br />
&lt;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&gt;<br />
&lt;Setter Property=&#8221;Foreground&#8221; Value=&#8221;Green&#8221;/&gt;<br />
&lt;/Trigger&gt;<br />
&lt;/ControlTemplate.Triggers&gt;<br />
&lt;/ControlTemplate&gt;<br />
&lt;/Button.Template&gt;<br />
&lt;/Button&gt;</p>
<p>Neither of them will work as expected, although they look fine. The reason here is that the property on the FrameworkElement overwrites the setters in Style or ControlTemplate, Therefore, any change caused by setters will not actually bring any change.  The following is the order in which WPF assign a value to a property.</p>
<p>1. The default value (as set by the FrameworkPropertyMetadata object)<br />
2. The inherited value (if the FrameworkPropertyMetadata.Inherits flag is set and a value has been applied to an element somewhere up the containment hierarchy)<br />
3. The value from a theme style (as discussed in Chapter 15)<br />
4. The value from a project style (as discussed in Chapter 12)<br />
5. The local value (in other words, a value you’ve set directly on this object using code or XAML)</p>
<p>To fix the above samples, the solution is quite as easy as the following</p>
<p>&lt;Grid&gt;<br />
&lt;Grid.Style&gt;<br />
&lt;Style TargetType=&#8221;{x:Type Grid}&#8221;&gt;<br />
&lt;Setter Property=&#8221;Background&#8221; Value=&#8221;Red&#8221;/&gt;<br />
&lt;Style.Triggers&gt;<br />
&lt;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&gt;<br />
&lt;Setter Property=&#8221;Background&#8221; Value=&#8221;Green&#8221;/&gt;<br />
&lt;/Trigger&gt;<br />
&lt;/Style.Triggers&gt;<br />
&lt;/Style&gt;<br />
&lt;/Grid.Style&gt;<br />
&lt;/Grid&gt;</p>
<p>As you can see, instead directly assign a value to the property, use setter in Style, whoese value can be overrwritten when the trigger executes its setter.</p>
<p>Another solution is to use setters on higher level, with TargetName property targetting the element. See following.</p>
<p>&lt;Button&gt;<br />
&lt;Button.Template&gt;<br />
&lt;ControlTemplate TargetType=&#8221;{x:Type Button}&#8221;&gt;<br />
&lt;Grid&gt;<br />
&lt;TextBlock x:Name=&#8221;textblock&#8221; Text=&#8221;Test&#8221; Foreground=&#8221;Red&#8221;/&gt;<br />
&lt;/Grid&gt;<br />
&lt;ControlTemplate.Triggers&gt;<br />
&lt;Trigger Property=&#8221;IsMouseOver&#8221; Value=&#8221;True&#8221;&gt;<br />
&lt;Setter Property=&#8221;Foreground&#8221; TargetName=&#8221;textblock&#8221; Value=&#8221;Green&#8221;/&gt;<br />
&lt;/Trigger&gt;<br />
&lt;/ControlTemplate.Triggers&gt;<br />
&lt;/ControlTemplate&gt;<br />
&lt;/Button.Template&gt;<br />
&lt;/Button&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=111&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/12/12/pitfall-with-using-triggers-in-style-and-controltemplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>Be smart with data binding</title>
		<link>http://wangmo.wordpress.com/2008/12/11/be-smart-with-data-binding/</link>
		<comments>http://wangmo.wordpress.com/2008/12/11/be-smart-with-data-binding/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 04:07:12 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[C# codes]]></category>
		<category><![CDATA[Databinding]]></category>
		<category><![CDATA[dependencyproperty]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=106</guid>
		<description><![CDATA[WPF&#8217;s data binding is so sweet that it should not be tied to the use of merely binding the UI to the data. Generically speaking, as long as it is dependency property, it can be data-bound. So, here is another situation where you would want to use data binding as well. Say, you want a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=106&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>WPF&#8217;s data binding is so sweet that it should not be tied to the use of merely binding the UI to the data. Generically speaking, as long as it is dependency property, it can be data-bound. So, here is another situation where you would want to use data binding as well.</p>
<p>Say, you want a property of a object to automatically update whenever its source changes. The very decent solution will be that you turn the target property to dependency property, and bind it to the source. To make the source able to notify the target of any change, you can either implement IPropertyChangeNotification, or wrap the source to a dependency property. In this way, the target property does not need any logic to keep itself updated.</p>
<p>So, next time you need to assign a value to a dependency property, make sure if you want its value to automatically update. If you do, now you know what you can also do.</p>
<p>One thing that needs to be paid attention to, though, is that you should remember to clear the bindings whenever the object is not needed any more. A good place to clear bindings is the Dispose method.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=106&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/12/11/be-smart-with-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>RoutedCommand Focus Scope</title>
		<link>http://wangmo.wordpress.com/2008/11/09/routedcommand-focus-scope/</link>
		<comments>http://wangmo.wordpress.com/2008/11/09/routedcommand-focus-scope/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 03:59:35 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[RoutedCommand]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=102</guid>
		<description><![CDATA[When you use RoutedCommand, the most important thing is to make sure that the command will route in the way you want, meaning that the command can find the commandbindng from which the corresponding action will be executed. However, although it also has routing capability, it routes somehow differently from RoutedEvent. Ernie pointed the possible [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=102&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you use RoutedCommand, the most important thing is to make sure that the command will route in the way you want, meaning that the command can find the commandbindng from which the corresponding action will be executed. However, although it also has routing capability, it routes somehow differently from RoutedEvent. <a href="http://blogs.msdn.com/ebooth/archive/2006/08/31/732609.aspx">Ernie </a>pointed the possible problem when using RoutedCommand, and the solutions.</p>
<p>Apparently, while CommandTarget works fine in one target situation, FocusManager.IsFocusScope seems the only choice for multi-targets circumstance. Unfortunately, Ernie did not explain in detail how IsFocusScope works. <a href="http://msdn.microsoft.com/en-us/magazine/cc785480.aspx">Brian</a> did the job. He said:</p>
<p>“Usually, a command invoker looks for a command binding between its own location in the visual tree and the root of the visual tree. If it finds one, the bound command handler will determine whether the command is enabled and will be called when the command is invoked. If the command is hooked up to a control inside a toolbar or menu (or, more generally, a container that sets FocusManager.IsFocusScope = true), then some additional logic runs that also looks along the visual tree path from the root to the focus element for a command binding.”</p>
<p><strong>NOTE:</strong> It only works for the commands which check the focus status to decide CanExecute, such as Cut and Copy. For commands of other kinds, it is useless.</p>
<p>I believe the above quoted words can explain how it works in Ernie post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=102&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/11/09/routedcommand-focus-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>How to stop flickering on Video by turning off AllowsTransparency</title>
		<link>http://wangmo.wordpress.com/2008/11/09/how-to-stop-flickering-on-video-by-turning-off-allowstransparency/</link>
		<comments>http://wangmo.wordpress.com/2008/11/09/how-to-stop-flickering-on-video-by-turning-off-allowstransparency/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 02:03:19 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[C# codes]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[UI control]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=98</guid>
		<description><![CDATA[If you need to put a Win32 video control, say a webcam, in WPF program, and you also need to put WPF controls over it, your only possiblity is to use Popup as the container for these controls, because Win32 controls always on the top of all the WPF controls(including adorners), regardless the Z order. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=98&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you need to put a Win32 video control, say a webcam, in WPF program, and you also need to put WPF controls over it, your only possiblity is to use Popup as the container for these controls, because Win32 controls always on the top of all the WPF controls(including adorners), regardless the Z order. The reason why Popup can &#8220;stay&#8221; over Win32 controls is that it actually spawn another independ window.</p>
<p>However, under the circumstance of current version of WPF, if you do not use popup carefully, it will always cause very annoying flicker over the video. This is because you probably set the AllowsTransparency property of Popup to true. <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5c795519-a642-4a7d-9f5f-a029168e5225/">Dr.WPF gave his understanding of this issue. </a>Then I do not repeate again.</p>
<p>Turning off AllowsTransparency of Popup is easy. How about MenuItem, ComboBox, ContextMenu and Tooltip? They all have internal popup which has AllowsTransparency set to true by default, but in different ways.</p>
<p>For MenuItem and ComboBox, you need to retemplate them with custom control template within which you explicitly set AllowsTransparency of Popup to false.</p>
<p>For ContextMenu and Tooltip, it will be more difficult becaue you cannot find popup in their templates. Therefore, you neend another method to deal with it. <a href="http://shevaspace.blogspot.com">You Zhong </a>provides a mothed to traverse the visual tree to get the popup instance. Although <a href="http://shevaspace.blogspot.com/2008/09/how-to-display-hwndhost-inside.html">in his post</a>, he did not directly address this issue, the method he came up with can certainly help. Here I quoted the two methods which are most important.</p>
<pre class="code"> <span style="color:blue;">private static void </span>SetAllowsTransparencyInternal(<span style="color:#2b91af;">Control </span>element, <span style="color:#2b91af;">Object </span>value)
    {
        <span style="color:#2b91af;">ToolTip </span>tooTip = element <span style="color:blue;">as </span><span style="color:#2b91af;">ToolTip</span>;
        <span style="color:#2b91af;">ContextMenu </span>contextMenu = element <span style="color:blue;">as </span><span style="color:#2b91af;">ContextMenu</span>;

        <span style="color:green;">// Set the IsOpen property to true to let the ToolTip/ContextMenu create Popup instance early, since
        // we are only interesting in Popup.AllowsTransparency property rather than
        // opening the ToolTip/ContextMenu, set its Visibility to Collapsed.
        </span>element.Visibility = <span style="color:#2b91af;">Visibility</span>.Collapsed;
        <span style="color:blue;">if </span>(tooTip != <span style="color:blue;">null</span>)
        {
            tooTip.IsOpen = <span style="color:blue;">true</span>;
        }
        <span style="color:blue;">else if </span>(contextMenu != <span style="color:blue;">null</span>)
        {
            contextMenu.IsOpen = <span style="color:blue;">true</span>;
        }

        <span style="color:green;">//Find the Popup logical element root.
        </span><span style="color:#2b91af;">Popup </span>popup = GetPopupFromVisualChild(element);
        <span style="color:blue;">if </span>(popup != <span style="color:blue;">null</span>) popup.SetValue(<span style="color:#2b91af;">Popup</span>.AllowsTransparencyProperty, value);

        <span style="color:green;">//Set properties back to what it is initially.
        </span><span style="color:blue;">if </span>(tooTip != <span style="color:blue;">null</span>)
        {
            tooTip.ClearValue(<span style="color:#2b91af;">ToolTip</span>.IsOpenProperty);
        }
        <span style="color:blue;">else if </span>(contextMenu != <span style="color:blue;">null</span>)
        {
            contextMenu.ClearValue(<span style="color:#2b91af;">ToolTip</span>.IsOpenProperty);
        }
        element.ClearValue(<span style="color:#2b91af;">FrameworkElement</span>.VisibilityProperty);
    }

    <span style="color:blue;">private static </span><span style="color:#2b91af;">Popup </span>GetPopupFromVisualChild(<span style="color:#2b91af;">Visual </span>child)
    {
        <span style="color:#2b91af;">Visual </span>parent = child;
        <span style="color:#2b91af;">FrameworkElement </span>visualRoot = <span style="color:blue;">null</span>;

        <span style="color:green;">//Traverse the visual tree up to find the PopupRoot instance.
        </span><span style="color:blue;">while </span>(parent != <span style="color:blue;">null</span>)
        {
            visualRoot = parent <span style="color:blue;">as </span><span style="color:#2b91af;">FrameworkElement</span>;
            parent = <span style="color:#2b91af;">VisualTreeHelper</span>.GetParent(parent) <span style="color:blue;">as </span><span style="color:#2b91af;">Visual</span>;
        }

        <span style="color:#2b91af;">Popup </span>popup = <span style="color:blue;">null</span>;

        <span style="color:green;">// Examine the PopupRoot's logical parent to get the Popup instance.
        // This might break in the future since it relies on the internal implementation of Popup's element tree.
        </span><span style="color:blue;">if </span>(visualRoot != <span style="color:blue;">null</span>)
        {
            popup = visualRoot.Parent <span style="color:blue;">as </span><span style="color:#2b91af;">Popup</span>;
        }

        <span style="color:blue;">return </span>popup;
    }</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=98&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/11/09/how-to-stop-flickering-on-video-by-turning-off-allowstransparency/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>Z-Order</title>
		<link>http://wangmo.wordpress.com/2008/10/31/z-order/</link>
		<comments>http://wangmo.wordpress.com/2008/10/31/z-order/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 22:02:39 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Adorner]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[UI control]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=95</guid>
		<description><![CDATA[Z-order In a WPF user interface, you can change the z-order of elements to control overlapping behavior. A hosted Windows Forms control is drawn in a separate HWND, so it is always drawn on top of WPF elements. A hosted Windows Forms control is also drawn on top of any Adorner elements. Refrence : http://msdn2.microsoft.com/en-us/library/ms744952.aspx [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=95&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Z-order</p>
<p class="subSection">In a WPF user interface, you can change the z-order of elements to control overlapping behavior. A hosted Windows Forms control is drawn in a separate HWND, so it is always drawn on top of WPF elements.</p>
<p class="subSection">A hosted Windows Forms control is also drawn on top of any Adorner elements.</p>
<p class="subSection">Refrence : <a title="http://msdn2.microsoft.com/en-us/library/ms744952.aspx" href="http://msdn2.microsoft.com/en-us/library/ms744952.aspx">http://msdn2.microsoft.com/en-us/library/ms744952.aspx</a></p>
<p class="subSection">http://social.msdn.microsoft.com/forums/en-US/wpf/thread/0cfdf58e-e32b-44f0-a0fc-d846d91452d6/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=95&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/10/31/z-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
		<item>
		<title>Relations between Adorner, AdornerLayer and AdornerDecorator</title>
		<link>http://wangmo.wordpress.com/2008/10/19/relations-between-adorner-adornerlayer-and-adornerdecorator/</link>
		<comments>http://wangmo.wordpress.com/2008/10/19/relations-between-adorner-adornerlayer-and-adornerdecorator/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 22:11:37 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Adorner]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[UI control]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=83</guid>
		<description><![CDATA[I read this article about Adorner. I&#8217;d like to make a note to make some concepts more straightforward. Adorner This is a base Adorner from which you will need to subclass. AdornerLayer The AdornerLayer can be considered as a plane in which the Adorners are drawn. Adorners are rendered in an AdornerLayer, which is a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=83&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I read <a href="http://www.artfulbits.com/Technologies/WinFX/Adorners.aspx">this article</a> about Adorner. I&#8217;d like to make a note to make some concepts more straightforward.</p>
<p><strong>Adorner</strong><br />
This is a base Adorner from which you will need to subclass.</p>
<p><strong>AdornerLayer</strong><br />
The AdornerLayer can be considered as a plane in which the Adorners are drawn. Adorners are rendered in an <strong>AdornerLayer</strong>, which is a rendering surface that         is always on top of the adorned element or a collection of adorned elements. Anything placed in the adorner layer is rendered on top of the         rest visual elements. In other words, adorners are always visually on top and cannot         be overridden using z-order.</p>
<p><strong>AdornerDecorator</strong><br />
Defines the location of an AdornerLayer in visual tree . <em>Window class already has                 it in the visual tree. It adds the default adorner layer above all other controls                 in the window.</em></p>
<p>The workflow is actually quite simple.</p>
<p>AdornerDecorator generates AdornerLayer at where it is in the visual tree. An <strong>AdornerDecorator</strong> can contain only <strong>one </strong>child, which is the parent element for the visual tree below the <strong>AdornerDecorator</strong>. AdornerDecorator divides a visual tree in two parallel branches one of which is the child         of the AdornerDecorator with it&#8217;s visual subtree, and the other one is <strong>AdornerLayer</strong>, like the figure below.</p>
<p><a href="http://wangmo.files.wordpress.com/2008/10/apressprowpfincsharp20082ndeditionfeb.jpg"><img class="aligncenter size-medium wp-image-84" title="apressprowpfincsharp20082ndeditionfeb" src="http://wangmo.files.wordpress.com/2008/10/apressprowpfincsharp20082ndeditionfeb.jpg?w=300&#038;h=291" alt="" width="300" height="291" /></a></p>
<h4>Adorning a Single UIElement</h4>
<p>To bind an adorner to a particular <strong>UIElement</strong>, follow these steps:</p>
<ul>
<li>Call the static method <strong>GetAdornerLayer</strong> of the <strong>AdornerLayer</strong> class to             get an <strong>AdornerLayer</strong> object for the <strong>UIElement</strong> to be adorned. <strong>GetAdornerLayer</strong> walks up the visual tree, starting at the specified <strong>UIElement</strong>, and returns             the <strong>first </strong>adorner layer it found. (If no adorner layers are found, the method returns             null.)</li>
<li>Create new instance of the adorner you need and pass it the instance of the UIElement             you need to adorn.</li>
<li>Call the <strong>Add</strong> method of the <strong>AdornerLayer</strong>, and pass it your newly created             adorner to bind it to the target <strong>UIElement</strong>.</li>
</ul>
<p>The following example binds  SomeAdorner (our own Adorner) to a <strong>TextBox</strong> named <em>myTextBox</em>.</p>
<div><code>myAdornerLayer = AdornerLayer.GetAdornerLayer(myTextBox); </code></div>
<div><code>myAdornerLayer.Add(new             SomeAdorner(myTextBox));</code></div>
<h4><a name="AdornersinWPF-AdorningtheChildrenofaPanel"></a>Adorning the Children of         a Panel</h4>
<p>To bind an adorner to the children of a <strong>Panel</strong>, follow these steps:</p>
<p>1. Call the <strong>static</strong> method <strong>GetAdornerLayer</strong> to find an adorner layer         for the element children of which are to be adorned.<br />
2. Enumerate the children of the parent element and call the <strong>Add</strong> method to         bind an adorner to each child element.</p>
<p>The following example binds a SomeAdorner (our own Adorne) to the children of a         <strong>StackPanel</strong> named <em>myStackPanel</em>.</p>
<div><code>foreach (UIElement toAdorn in myStackPanel.Children) </code></div>
<div><code>myAdornerLayer.Add(new SomeAdorner(toAdorn));</code></div>
<p>Another thing worth of reminding is Validation.ErrorTemplate is rendered on AdornerLayer. So if you want your error template displayed, do not forget to give it a AdornerLayer, like <a href="http://karlshifflett.wordpress.com/?s=AdornerDecorator">what Karl does</a>, or <a href="http://blog.pixelingene.com/?p=44">what Pavan does</a> if you want your DnD works.</p>
<p>To quickly pick up Adorner, <a href="http://wpfxaml.spaces.live.com/blog/cns!97DD5FD32788695B!141.entry">this article</a> is probably a good start.</p>
<p><strong>Update</strong>: although you can put an AdornerDecorator in XAML to let WPF itself create the AdornerLayer, you can also write code to do the job.</p>
<p>AdornerDecorator decorator = new AdornerDecorator();</p>
<p>decorator.Child = panel;</p>
<p>this.Content = decorator;</p>
<p>AdornerLayer layer = AdornerLayer.GetAdornerLayer(panel);</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=83&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/10/19/relations-between-adorner-adornerlayer-and-adornerdecorator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>

		<media:content url="http://wangmo.files.wordpress.com/2008/10/apressprowpfincsharp20082ndeditionfeb.jpg?w=300" medium="image">
			<media:title type="html">apressprowpfincsharp20082ndeditionfeb</media:title>
		</media:content>
	</item>
		<item>
		<title>ControlTemplate and DataTemplate</title>
		<link>http://wangmo.wordpress.com/2008/10/13/controltemplate-and-datatemplate/</link>
		<comments>http://wangmo.wordpress.com/2008/10/13/controltemplate-and-datatemplate/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 05:58:30 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[dependencyproperty]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[Template]]></category>
		<category><![CDATA[UI control]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://wangmo.wordpress.com/?p=80</guid>
		<description><![CDATA[Sometimes it seems that some elements can be placed in the ControlTemplate, and also can be placed in the DataTemplate. This causes great confustion for WPF beginners. But actually there is a clear line between the both, and it is not that some elements can be placed in either of them. ControlTemplate reflects the behaviors [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=80&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes it seems that some elements can be placed in the ControlTemplate, and also can be placed in the DataTemplate. This causes great confustion for WPF beginners. But actually there is a clear line between the both, and it is not that some elements can be placed in either of them.</p>
<p>ControlTemplate reflects the behaviors and appearance of a control. It should <strong>not </strong>have knowledge of the content(data), if it has, because the data is wrapped and represented by ContentPresenter/ItemsPresenter in the ControlTemplate.</p>
<p>DataTemplate is the representation of the data. Similarly, DataTemplate should <strong>not </strong>have knowledge of its residing control, because DataTemplate only represents the data, and can be placed in any ContentControl.</p>
<p>Karl said :&#8221;When authoring your control, attempt to design a control that derives its behavior and appearance from its own dependency properties.&#8221; <strong>This means that dependencyproperty is designed for its control&#8217;s behaviors and apperance,</strong> NOT for its content(data)&#8217;s behaviors and apperance. <strong>All the dependencyproperty-related behaviors and appearance should be defined in the ControlTemplate, whereas all the data-related behaviors and appearance should be defined in the DataTemplate. Note:</strong> By Data here I mean Content&#8217;s data.</p>
<p>This actually makes up a rule for the default ControlTemplate of the custom control:<strong><br />
When working on the default ControlTemplate for the custom control, do NOT involve DataTemplate, </strong>because you do not know what the content(data) will be and how it will be represented. The content(data) is just abstracted as ContentPresenter/ItemsPresenter in the ControlTemplate.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/wangmo.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/wangmo.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/wangmo.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=wangmo.wordpress.com&amp;blog=56446&amp;post=80&amp;subd=wangmo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://wangmo.wordpress.com/2008/10/13/controltemplate-and-datatemplate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb17e3676bb16f14cebae444759ce253?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">wangmo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
