<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Alan Le &#187; Code</title>
	<atom:link href="http://alanle.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://alanle.com</link>
	<description>my personal blog</description>
	<lastBuildDate>Sat, 11 Jul 2009 01:04:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Naming your WPF and Silverlight resources</title>
		<link>http://alanle.com/2009/02/15/naming-your-wpf-and-silverlight-resources/</link>
		<comments>http://alanle.com/2009/02/15/naming-your-wpf-and-silverlight-resources/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:11:35 +0000</pubDate>
		<dc:creator>alan.le</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://alanle.com/?p=132</guid>
		<description><![CDATA[I’ve written about WPF resource organization and keeping XAML clean before. Recently I came across a WPF sample application that had an interesting naming convention for brush resources.
Instead of naming a brush resource as MainWindowBackgroundBrush, they would use the name Background_MainWindow. At first, this may seem like an odd convention, especially with the underscore. However [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://alanle.com/wp-content/uploads/2009/02/image.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 15px; border-right-width: 0px" height="432" alt="image" src="http://alanle.com/wp-content/uploads/2009/02/image-thumb.png" width="329" align="right" border="0" /></a>I’ve written about <a href="http://blogs.vertigo.com/personal/alanl/Blog/archive/2007/11/26/wpf-resource-organization-organized-as-separate-files-by-type-vs-single-file.aspx">WPF resource organization</a> and <a href="http://blogs.vertigo.com/personal/alanl/Blog/archive/2007/11/30/keeping-xaml-clean.aspx">keeping XAML clean</a> before. Recently I came across a <a href="http://windowsclient.net/appfeeds/SubscriptionCenter/Gallery/photosuru.aspx">WPF sample application</a> that had an interesting naming convention for brush resources.</p>
<p>Instead of naming a brush resource as <strong>MainWindowBackgroundBrush, </strong>they would use the name <strong>Background_MainWindow. </strong>At first, this may seem like an odd convention, especially with the underscore. However taken as a whole, this convention can be really useful in Expression Blend.</p>
<p>During the implementation process when applying brushes to WPF elements, the brushes can be quickly and easily set. Just select Brush Resources and find the correct brush. Since the brushes are in alphabetically order, all of the background brushes are in the same area. Likewise for the border and foreground brushes.</p>
<p>Also with this convention, we can remove the “Brush” word in the name since we can easily tell that a resource is a brush because the brush resources start with Border_, Background_, or Foreground_.</p>
<p>I think I will start following this naming convention in future WPF and Silverlight projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://alanle.com/2009/02/15/naming-your-wpf-and-silverlight-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://alanle.com/wp-content/uploads/2009/02/image-thumb.png" />
		<media:content url="http://alanle.com/wp-content/uploads/2009/02/image-thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Design Time Check for WPF and Silverlight</title>
		<link>http://alanle.com/2009/02/10/design-time-check-for-wpf-and-silverlight/</link>
		<comments>http://alanle.com/2009/02/10/design-time-check-for-wpf-and-silverlight/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 15:11:00 +0000</pubDate>
		<dc:creator>alan.le</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://alanle.com/?p=110</guid>
		<description><![CDATA[Do you commonly check whether code is being run in Blend or in the Visual Studio design surface? Often times, this is necessary to load up sample data or to prevent code that could potentially break the “Blendability” of a WPF or Silverlight app.
In WPF, you can call the DesignerProperties.GetIsInDesignMode for it. In Silverlight, you [...]]]></description>
			<content:encoded><![CDATA[<p>Do you commonly check whether code is being run in Blend or in the Visual Studio design surface? Often times, this is necessary to load up sample data or to prevent code that could potentially break the “Blendability” of a WPF or Silverlight app.</p>
<p>In WPF, you can call the <strong>DesignerProperties.GetIsInDesignMode </strong>for it. In Silverlight, you can check for <strong>HtmlPage.IsEnabled</strong> property.</p>
<p>I check for design mode often and needed a simple, consistent method to mask the DesignerProperties call in WPF. In Silverlight, I wanted to hide the hacky HtmlPage.IsEnabled check and change it from being a not(!) check to a positive check. Also, when Silverlight support the DesignerProperties.GetIsInDesignMode method, I can just easily change my check in one place. With some refinements from friends at work, I condensed it to a single static property in <em>App.xaml.cs </em>that I can use throughout my application.</p>
<p><em>In App.xaml.cs:</em></p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: consolas,'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;">
<div style="border-style: none; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">bool</span> IsInDesignMode</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    get</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">        <span style="color: #cc6633">#if</span> Silverlight</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">            <span style="color: #0000ff">return</span> !HtmlPage.IsEnabled;;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">        <span style="color: #cc6633">#else</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">            <span style="color: #0000ff">return</span> DesignerProperties.GetIsInDesignMode(<span style="color: #0000ff">new</span> DependencyObject());</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">        <span style="color: #cc6633">#endif</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">}</pre>
</div>
</div>
<p>Note that the precompiler directives can be removed if you’re just targeting WPF or just targeting Silverlight</p>
<p>Here’s how I use it:</p>
<div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; line-height: 12pt; background-color: #f4f4f4; width: 97.5%; font-family: consolas,'Courier New',courier,monospace; max-height: 200px; font-size: 8pt; cursor: text;">
<div style="border-style: none; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;"><span style="color: #0000ff">void</span> MainView_Loaded(<span style="color: #0000ff">object</span> sender, RoutedEventArgs e)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    <span style="color: #0000ff">if</span> (App.IsInDesignMode)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">        LoadSampleData();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    <span style="color: #0000ff">else</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">        LoadRunTimeData();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">    }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; line-height: 12pt; background-color: white; width: 100%; font-family: consolas,'Courier New',courier,monospace; color: black; font-size: 8pt;">}</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://alanle.com/2009/02/10/design-time-check-for-wpf-and-silverlight/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
	</item>
	</channel>
</rss>
