<?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>LegHumped.com &#187;  &#187; Leghumped</title>
	<atom:link href="http://www.leghumped.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leghumped.com/blog</link>
	<description>Coding snippets, tutorials and procrastinations about C#, Java and Linux.</description>
	<lastBuildDate>Wed, 11 Jan 2012 20:15:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Finding Next Available Name in Objective-C</title>
		<link>http://www.leghumped.com/blog/2012/01/11/finding-next-available-name-in-objective-c/</link>
		<comments>http://www.leghumped.com/blog/2012/01/11/finding-next-available-name-in-objective-c/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 20:15:37 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=481</guid>
		<description><![CDATA[Useful method for finding the next available unique name in a batch of strings. Eg: give it A list of { &#8220;Name&#8221;, &#8220;Name 1&#8243;, &#8220;Name 2&#8243; } and it will return &#8220;Name 3&#8243;. +&#40;NSString*&#41;getNextAVailableName:&#40;NSString*&#41;name fromNames:&#40;NSMutableArray*&#41;otherNames &#123; if &#40;&#91;otherNames indexOfObjectPassingTest:^BOOL&#40;id obj, NSUInteger idx, BOOL *stop&#41; &#123; return &#91;&#91;name lowercaseString&#93; isEqualToString:&#40;NSString*&#41;obj&#93;; &#125;&#93; == NSNotFound&#41; &#123; return name; [...]]]></description>
			<content:encoded><![CDATA[<p>Useful method for finding the next available unique name in a batch of strings.</p>
<p>Eg: give it A list of { &#8220;Name&#8221;, &#8220;Name 1&#8243;, &#8220;Name 2&#8243; } and it will return &#8220;Name 3&#8243;.</p>
<p><span id="more-481"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>getNextAVailableName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>name fromNames<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>otherNames <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>otherNames indexOfObjectPassingTest<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> obj, NSUInteger idx, <span style="color: #a61390;">BOOL</span> <span style="color: #002200;">*</span>stop<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>name lowercaseString<span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>obj<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NSNotFound<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> name;
    <span style="color: #002200;">&#125;</span>
    bool gotName<span style="color: #002200;">=</span><span style="color: #a61390;">false</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>currentName <span style="color: #002200;">=</span> name;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">2</span>; <span style="color: #002200;">!</span>gotName; <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        currentName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@ %d&quot;</span>, name , i<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>otherNames indexOfObjectPassingTest<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> obj, NSUInteger idx, <span style="color: #a61390;">BOOL</span> <span style="color: #002200;">*</span>stop<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>currentName lowercaseString<span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>obj<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            i<span style="color: #002200;">++</span>;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            name <span style="color: #002200;">=</span> currentName;
            gotName <span style="color: #002200;">=</span> <span style="color: #a61390;">true</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> name;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2012/01/11/finding-next-available-name-in-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internal Subnav with BlogEngine.NET</title>
		<link>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/</link>
		<comments>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 15:15:39 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[blogengine.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=479</guid>
		<description><![CDATA[One of the great ASP.NET web apps I&#8217;ve started using is BlogEngine.NET, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn&#8217;t make particularly easy, such as displaying navigation trees. This can be largely overcome by extending some of the controls which BlogEngine ships [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great ASP.NET web apps I&#8217;ve started using is <a href="http://blogengine.codeplex.com/">BlogEngine.NET</a>, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn&#8217;t make particularly easy, such as displaying navigation trees.</p>
<p>This can be largely overcome by extending some of the controls which BlogEngine ships with, such as the post list. I changed this to display a list of sub pages for the current page. Once you set a page&#8217;s parent page, the subnav is rendered on the masterpage.</p>
<p><span id="more-479"></span></p>
<p>We just need one control on <em>page.aspx</em> and some code to bind it in the code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;blog:PageList runat=&quot;server&quot; ID=&quot;pageList&quot; /&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ServePage<span style="color: #008000;">&#40;</span>Guid id<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
 	<span style="color: #008000;">...</span>
  	<span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>pg<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> Guid<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// root page</span>
            pageList<span style="color: #008000;">.</span><span style="color: #0000FF;">RootPageID</span> <span style="color: #008000;">=</span> id<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// sub page of root level page</span>
            pageList<span style="color: #008000;">.</span><span style="color: #0000FF;">RootPageID</span> <span style="color: #008000;">=</span> pg<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Out of the box, the html for the tree is generated once which won&#8217;t work if it&#8217;s different for every page, so you&#8217;ll also need to modify <em>PageList.cs</em> in the <em>~/App_Code/Controls</em> folder. I kept the caching and replaced it with a dictionary for each page to map between page ID and HTML for the page list.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">static</span> PageList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Saved</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> PageList<span style="color: #008000;">.</span><span style="color: #0000FF;">ClearCachedHtml</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ClearCachedHtml<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ClearCachedHtml<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PageList&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//We also need a few more properties:</span>
	<span style="color: #008080;">#region Properties</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> Dictionary<span style="color: #008000;">&lt;</span>Guid,<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> HtmlDictionary
        <span style="color: #008000;">&#123;</span>
            get
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> cacheKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;pageListDict&quot;</span><span style="color: #008000;">;</span>
                var htmlDict <span style="color: #008000;">=</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">&#91;</span>cacheKey<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span>Guid, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>htmlDict <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    htmlDict <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span>Guid, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">&#91;</span>cacheKey<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> htmlDict<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> htmlDict<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetPageListForPage<span style="color: #008000;">&#40;</span>Guid pageId<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> html<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>HtmlDictionary<span style="color: #008000;">.</span><span style="color: #0000FF;">TryGetValue</span><span style="color: #008000;">&#40;</span>pageId, <span style="color: #0600FF; font-weight: bold;">out</span> html<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                html <span style="color: #008000;">=</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Utils</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RenderControl</span><span style="color: #008000;">&#40;</span>BindPages<span style="color: #008000;">&#40;</span>pageId<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                HtmlDictionary<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>pageId, html<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> html<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> Guid<span style="color: #008000;">?</span> RootPageID
        <span style="color: #008000;">&#123;</span>
            get
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span>
                           <span style="color: #008000;">?</span> <span style="color: #008000;">&#40;</span>Guid<span style="color: #008000;">?</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">null</span>
                           <span style="color: #008000;">:</span> <span style="color: #008000;">new</span> Guid<span style="color: #008000;">&#40;</span>Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span></pre></div></div>

<p>The root page ID specifies the parent pages whose children to render.</p>
<p>The final step is some changes to the private methods which render the lists:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderControl<span style="color: #008000;">&#40;</span>HtmlTextWriter writer<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            writer<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>GetPageListForPage<span style="color: #008000;">&#40;</span>RootPageID<span style="color: #008000;">??</span>Guid<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
           <span style="color: #008080; font-style: italic;">// writer.Write(Environment.NewLine);</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> HtmlGenericControl BindPages<span style="color: #008000;">&#40;</span>Guid<span style="color: #008000;">?</span> pageId<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//HtmlGenericControl div = new HtmlGenericControl(&quot;div&quot;);</span>
            var div <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ul&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            div<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>,<span style="color: #666666;">&quot;softwareList&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            div<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;pagelist&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> page <span style="color: #0600FF; font-weight: bold;">in</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Pages</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>page<span style="color: #008000;">.</span><span style="color: #0000FF;">ShowInList</span> <span style="color: #008000;">&amp;&amp;</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">IsVisibleToPublic</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span> <span style="color: #008000;">&amp;&amp;</span> pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span> <span style="color: #008000;">&amp;&amp;</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;00000000-0000-0000-0000-000000000000&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    div<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>BuildSubPages<span style="color: #008000;">&#40;</span>div, page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> div<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> HtmlGenericControl BuildSubPages<span style="color: #008000;">&#40;</span>Control parentElement, BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> page<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">&gt;</span> subPages <span style="color: #008000;">=</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Pages</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            HtmlGenericControl li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            HtmlAnchor anc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlAnchor<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">HRef</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">RelativeLink</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerHtml</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Description</span><span style="color: #008000;">;</span>
            li<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>anc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>subPages<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                HtmlGenericControl ul <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ul&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                li<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ul<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> p <span style="color: #0600FF; font-weight: bold;">in</span> subPages<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    HtmlGenericControl innerLi <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    ul<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>BuildSubPages<span style="color: #008000;">&#40;</span>innerLi, p<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            parentElement<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>li<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> li<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Though this should work for unlimited navigation levels, I&#8217;ve only tested it with two. Ideally, <a href="http://www.umbraco.com/">Umbraco</a> is suited excellently to this due to it&#8217;s ability to use XSLT for jobs like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved componentsJoinedByString:</title>
		<link>http://www.leghumped.com/blog/2011/12/25/improved-componentsjoinedbystring/</link>
		<comments>http://www.leghumped.com/blog/2011/12/25/improved-componentsjoinedbystring/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 15:21:57 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[chickenping]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[implode]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=473</guid>
		<description><![CDATA[To format list of categories, ingredients etc in a more readable way for ChickenPing, I use a function which joins a list of strings using a separator and a final separator. Eg: NSArray *items = &#91;&#91;NSArray alloc&#93; initWithObjects:@&#34;Item1&#34;, @&#34;Item2&#34;, @&#34;Item3&#34;, nil&#93;; NSString *joined = &#91;Utils implode:items withSeperator:@&#34;, &#34; trimStrings:true lastSeparator:@&#34; and &#34;&#93;; // returns &#34;Item1, [...]]]></description>
			<content:encoded><![CDATA[<p>To format list of categories, ingredients etc in a more readable way for <a href="http://www.ChickenPing.com">ChickenPing</a>, I use a function which joins a list of strings using a separator and a final separator. Eg:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>items <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Item1&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Item2&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Item3&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>joined <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Utils implode<span style="color: #002200;">:</span>items withSeperator<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;, &quot;</span> trimStrings<span style="color: #002200;">:</span><span style="color: #a61390;">true</span> lastSeparator<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot; and &quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// returns &quot;Item1, Item2 and Item3&quot;</span></pre></div></div>

<p>It&#8217;s more flexible than <em>NSArraycomponentsJoinedByString:</em> because it includes an optional last separator and the option to trim strings. Code is below.</p>
<p><span id="more-473"></span></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #11740a; font-style: italic;">/// Joins a list using a separator.</span>
<span style="color: #11740a; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #11740a; font-style: italic;">/// &lt;param name=&quot;items&quot;&gt;The list to join.&lt;/param&gt;</span>
<span style="color: #11740a; font-style: italic;">/// &lt;param name=&quot;separator&quot;&gt;The separator to use.&lt;/param&gt;</span>
<span style="color: #11740a; font-style: italic;">/// &lt;param name=&quot;trim&quot;&gt;If set to &lt;c&gt;true&lt;/c&gt;, trims whitespace from each index.&lt;/param&gt;</span>
<span style="color: #11740a; font-style: italic;">/// &lt;returns&gt;A string containing the values separated by the separator&lt;/returns&gt;</span>
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>implode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>items withSeperator<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>separator trimStrings<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>trim <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>Utils implode<span style="color: #002200;">:</span>items withSeperator<span style="color: #002200;">:</span>separator trimStrings<span style="color: #002200;">:</span>trim lastSeparator<span style="color: #002200;">:</span>separator<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">/* &lt;summary&gt;
 *  Joins a list using a separator.
 * &lt;/summary&gt;
 * &lt;param name=&quot;items&quot;&gt;The list to join.&lt;/param&gt;
 * &lt;param name=&quot;separator&quot;&gt;The separator to use.&lt;/param&gt;
 * &lt;param name=&quot;trim&quot;&gt;If set to &lt;c&gt;true&lt;/c&gt;, trims whitespace from each index.&lt;/param&gt;
 * &lt;param name=&quot;lastSeparator&quot;&gt;The separator to use to join the second to last and last item, or &lt;c&gt;null&lt;/c&gt; to use the separator. Eg: Could be &quot;and&quot;.&lt;/param&gt;
 * &lt;returns&gt;A string containing the values separated by the separator&lt;/returns&gt;
 */</span>
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>implode<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>items withSeperator<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>separator trimStrings<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>trim lastSeparator<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>separatorForLastItem <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>buffer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">int</span> num <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>items count<span style="color: #002200;">&#93;</span>,
        added <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>item <span style="color: #a61390;">in</span> items<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>buffer appendString<span style="color: #002200;">:</span>trim ? <span style="color: #002200;">&#91;</span>item stringByTrimmingCharactersInSet<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSCharacterSet</span> whitespaceAndNewlineCharacterSet<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>
                                      <span style="color: #002200;">:</span> item<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>added <span style="color: #002200;">+</span> <span style="color: #2400d9;">1</span> &lt; num<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>added <span style="color: #002200;">==</span> num <span style="color: #002200;">-</span> <span style="color: #2400d9;">2</span> <span style="color: #002200;">&amp;&amp;</span> separatorForLastItem <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>buffer appendString<span style="color: #002200;">:</span>separatorForLastItem<span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
                <span style="color: #002200;">&#91;</span>buffer appendString<span style="color: #002200;">:</span>separator<span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#125;</span>
        <span style="color: #002200;">&#125;</span>
        added<span style="color: #002200;">++</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>buffer copy<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/12/25/improved-componentsjoinedbystring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Collapsible Panel Plugin</title>
		<link>http://www.leghumped.com/blog/2011/11/26/jquery-collapsible-panel-plugin/</link>
		<comments>http://www.leghumped.com/blog/2011/11/26/jquery-collapsible-panel-plugin/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 13:43:38 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=469</guid>
		<description><![CDATA[One of the things I find myself constantly doing with jQuery is making divs expand and collapse based on clicks on other elements. Collapsible panels are a great way of achieving progressive disclosure. I got sick of writing the same code on multiple pages so I wrote a plugin instead. This creates an accordian style [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I find myself constantly doing with jQuery is making divs expand and collapse based on clicks on other elements. Collapsible panels are a great way of achieving <a href="http://uxdesign.smashingmagazine.com/2009/06/23/10-ui-design-patterns-you-should-be-paying-attention-to/" title="Smashing Magazine - 10 UI Design Patterns You Should Be Paying Attention To">progressive disclosure</a>. I got sick of writing the same code on multiple pages so I wrote a plugin instead.</p>
<p>This creates an accordian style header which expands a linked panel when clicked.</p>
<p><a href="http://leghumped.com/collapsify-demo.html">Demo</a><br />
<a href="http://leghumped.com/jquery.collapsiblepanel.js">Download</a><br />
<span id="more-469"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        collapsiblePanel<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> indicator <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-expander'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> header <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-widget-header'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> content <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ui-widget-content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>content.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':visible'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    indicator.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>                                       
                    indicator.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                header.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    content.<span style="color: #660066;">slideToggle</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>content.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':visible'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            indicator.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>                                       
                            indicator.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-e ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ui-icon-triangle-1-s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You also need a set structure for your panel (below).</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;ui-widget collapse&quot;&gt;
    &lt;div id=&quot;expander-demo-control&quot; class=&quot;ui-widget-header&quot;&gt;
        &lt;span class=&quot;ui-icon ui-expander floatLeft&quot;&gt;+&lt;/span&gt;
        &lt;span style=&quot;display: inline&quot;&gt;Lime49 Expandy Widgets Inc.&lt;/span&gt;
    &lt;/div&gt;
    &lt;div id=&quot;expander-demo&quot; class=&quot;ui-widget-content&quot;&gt;
        &lt;p&gt;Snap! the overstrained line sagged down in one long festoon; the tugging log was gone.&lt;/p&gt;
&nbsp;
	&lt;p&gt;&quot;I crush the quadrant, the thunder turns the needles, and now the mad sea parts the log-line. But Ahab can mend all. Haul in here, Tahitian; reel up, Manxman. And look ye, let the carpenter make another log, and mend thou the line. See to it.&quot;&lt;/p&gt;
&nbsp;
	&lt;p&gt;&quot;There he goes now; to him nothing's happened; but to me, the skewer seems loosening out of the middle of the world. Haul in, haul in, Tahitian! These lines run whole, and whirling out: come in broken, and dragging slow. Ha, Pip? come to help; eh, Pip?&quot;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>Call it using:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.collapse'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">collapsiblePanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/11/26/jquery-collapsible-panel-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zipcode distance matching with SQL Server</title>
		<link>http://www.leghumped.com/blog/2011/11/06/zipcode-distance-matching-with-sql-server/</link>
		<comments>http://www.leghumped.com/blog/2011/11/06/zipcode-distance-matching-with-sql-server/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 16:21:58 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=465</guid>
		<description><![CDATA[I recently needed to add a nearest postcode/zip lookup using SQL Server based on latitude and longitude. This finally gave me a chance to play around with the Geography datatype in SQL Server 2008. There are various places to source data from. This usually depends how much information you get, but 10 minutes of googling [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to add a nearest postcode/zip lookup using SQL Server based on latitude and longitude. This finally gave me a chance to play around with the Geography datatype in SQL Server 2008.</p>
<p>There are various places to source data from. This usually depends how much information you get, but 10 minutes of googling found me 60000 city/state/zip/lat/long records. For reference, my table looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>ZipCodes<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>Zip<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>City<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>State<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>nvarchar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Latitude<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Longitude<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>Timezone<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
	<span style="color: #66cc66;">&#91;</span>IsDST<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span>bit<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
 <span style="color: #993333; font-weight: bold;">CONSTRAINT</span> <span style="color: #66cc66;">&#91;</span>PK_ZIpCodes<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> CLUSTERED 
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #66cc66;">&#91;</span>Zip<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #66cc66;">&#40;</span>PAD_INDEX  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> STATISTICS_NORECOMPUTE  <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> IGNORE_DUP_KEY <span style="color: #66cc66;">=</span> OFF<span style="color: #66cc66;">,</span> ALLOW_ROW_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">,</span> ALLOW_PAGE_LOCKS  <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">ON</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p><span id="more-465"></span><br />
There are also indexes on city, state, latitude, longitude and latitude/longitude. I&#8217;m not an expert with SQL so the last one is just for good measure. This lets me query on any column with half decent results.</p>
<p>Once you&#8217;ve got from the CSV or SQL script you found/purchased in to your database you need to add a Geography column.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> ZipCodes
<span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #66cc66;">&#91;</span>GeoLocation<span style="color: #66cc66;">&#93;</span> GEOGRAPHY
<span style="color: #993333; font-weight: bold;">GO</span></pre></div></div>

<p>Then you can build fill the column using the data you have for latitude and longitude:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> ZipCodes
<span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #66cc66;">&#91;</span>GeoLocation<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> geography::STPointFromText<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'POINT('</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>Longitude<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>Latitude<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">')'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4326</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Now you have to decide whether to build the query using inline SQL in your code or create a stored procedure for it. My instinct says stored procedure but right now inline SQL is fine.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @myposition geography;
<span style="color: #993333; font-weight: bold;">SELECT</span> @myposition <span style="color: #66cc66;">=</span> GeoLocation <span style="color: #993333; font-weight: bold;">FROM</span> ZipCodes
<span style="color: #993333; font-weight: bold;">WHERE</span> Zip <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'10005'</span> ;<span style="color: #808080; font-style: italic;">--OR City LIKE 'New York' OR State LIKE 'NY';  </span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> z<span style="color: #66cc66;">.*,</span>z<span style="color: #66cc66;">.</span>GeoLocation<span style="color: #66cc66;">.</span>STDistance<span style="color: #66cc66;">&#40;</span>@myposition<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Distance <span style="color: #993333; font-weight: bold;">FROM</span> ZipCodes z
<span style="color: #993333; font-weight: bold;">WHERE</span> z<span style="color: #66cc66;">.</span>GeoLocation<span style="color: #66cc66;">.</span>STDistance<span style="color: #66cc66;">&#40;</span>@myposition<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;=</span> <span style="color: #cc66cc;">1000</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Distance <span style="color: #993333; font-weight: bold;">ASC</span></pre></div></div>

<p>In this case, the query is built in .NET with certain parts left out depending what the user searched for, but that&#8217;s irrelevant. The last part is commented out because you want to get the most precise match, so if you have a zip code, use it. If not you can use the City and State columns.</p>
<pre>
Zip	City	State	Latitude	Longitude	Timezone	IsDST	GeoLocation					Distance
10005	New York	NY	40.706019	-74.00858	-5	1	0xE6100000010CEE7C3F355E5A4440B8AF03E78C8052C0	0
10270	New York	NY	40.706925	-74.008154	-5	1	0xE6100000010C6DC5FEB27B5A4440F1F44A59868052C0	105.505094488081
10045	New York	NY	40.70859	-74.008687	-5	1	0xE6100000010C09F9A067B35A44406ADE718A8E8052C0	288.849104985383
10271	New York	NY	40.708669	-74.01043	-5	1	0xE6100000010C6D567DAEB65A444038F8C264AA8052C0	336.208294678286
10041	New York	NY	40.703042	-74.01009	-5	1	0xE6100000010C448B6CE7FB594440226C787AA58052C0	356.447222439371
10006	New York	NY	40.707904	-74.01342	-5	1	0xE6100000010C516B9A779C5A44400D71AC8BDB8052C0	457.225354635998
10038	New York	NY	40.709677	-74.00365	-5	1	0xE6100000010C50FC1873D75A444000917EFB3A8052C0	589.364962050259
10048	New York	NY	40.712086	-74.01227	-5	1	0xE6100000010CA5BDC117265B4440696FF085C98052C0	746.071595261018
10250	New York	NY	40.709387	-74.016529	-5	1	0xE6100000010C26E4839ECD5A4440931804560E8152C0	766.967118714565
10279	New York	NY	40.713062	-74.00857	-5	1	0xE6100000010C88635DDC465B4440B8AF03E78C8052C0	788.442916610519
10280	New York	NY	40.707467	-74.0178	-5	1	0xE6100000010CC3F5285C8F5A44409A779CA2238152C0	795.10810871016
10286	New York	NY	40.714231	-74.011895	-5	1	0xE6100000010CCF66D5E76A5B4440A2B437F8C28052C0	952.338009037327
10007	New York	NY	40.714754	-74.00721	-5	1	0xE6100000010C2497FF907E5B4440FF21FDF6758052C0	984.36004707576
</pre>
<p>These all seem roughly around the same place and are ordered by distance, but what do I know, I&#8217;ve never been to New York!</p>
<p>I&#8217;ve found it quicker to use a temporary table when doing the actual SELECT, ie:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @miles <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
<span style="color: #993333; font-weight: bold;">DECLARE</span> @myposition geography;
<span style="color: #993333; font-weight: bold;">SELECT</span> @myposition <span style="color: #66cc66;">=</span> GeoLocation <span style="color: #993333; font-weight: bold;">FROM</span> ZipCodes
<span style="color: #993333; font-weight: bold;">WHERE</span> Zip <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'11204'</span>;
<span style="color: #808080; font-style: italic;">--WHERE City LIKE 'Zionville';-- OR State LIKE 'NY';</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> z<span style="color: #66cc66;">.*,</span>z<span style="color: #66cc66;">.</span>GeoLocation<span style="color: #66cc66;">.</span>STDistance<span style="color: #66cc66;">&#40;</span>@myposition<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Distance <span style="color: #993333; font-weight: bold;">INTO</span> #HASHTABLE <span style="color: #993333; font-weight: bold;">FROM</span> ZipCodes z
<span style="color: #993333; font-weight: bold;">WHERE</span> z<span style="color: #66cc66;">.</span>GeoLocation<span style="color: #66cc66;">.</span>STDistance<span style="color: #66cc66;">&#40;</span>@myposition<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;=</span> <span style="color: #66cc66;">&#40;</span>@miles<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1609.344</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Distance <span style="color: #993333; font-weight: bold;">ASC</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> z<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Latitude<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> z<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>Longitude<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> u<span style="color: #66cc66;">.*,</span> z<span style="color: #66cc66;">.</span>GeoLocation<span style="color: #66cc66;">.</span>STDistance<span style="color: #66cc66;">&#40;</span>@myposition<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Distance
<span style="color: #993333; font-weight: bold;">FROM</span> Users u <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> ZipCodes z <span style="color: #993333; font-weight: bold;">ON</span> u<span style="color: #66cc66;">.</span>PostCode <span style="color: #66cc66;">=</span> z<span style="color: #66cc66;">.</span>Zip
<span style="color: #993333; font-weight: bold;">WHERE</span> u<span style="color: #66cc66;">.</span>PostCode <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> Zip <span style="color: #993333; font-weight: bold;">FROM</span> #hashtable<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OR</span> u<span style="color: #66cc66;">.</span>City <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> City <span style="color: #993333; font-weight: bold;">FROM</span> #hashtable<span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> #Hashtable</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/11/06/zipcode-distance-matching-with-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pagination and Delegates in a UITableView</title>
		<link>http://www.leghumped.com/blog/2011/10/16/pagination-and-delegates-in-a-uitableview/</link>
		<comments>http://www.leghumped.com/blog/2011/10/16/pagination-and-delegates-in-a-uitableview/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 18:25:37 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=460</guid>
		<description><![CDATA[I recently needed to create a table view where the user could scroll to the bottom to load more data, similar to Facebook&#8217;s &#8216;pull to refresh&#8217;. This shows a loading indicator while more data is retrieved. To do this I used a delegate which is implemented by a custom table view cell. The ViewController contains [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to create a table view where the user could scroll to the bottom to load more data, similar to Facebook&#8217;s &#8216;pull to refresh&#8217;. This shows a loading indicator while more data is retrieved. To do this I used a delegate which is implemented by a custom table view cell.<br />
<span id="more-460"></span><br />
The ViewController contains a method to load more data, which might be called when the user scrolls to the bottom. This finds the last cell and calls the toggleLoading method.<br />
<strong>CustomTableViewController.h</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>toggleTableViewLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>isLoading;</pre></div></div>

<p><strong>CustomTableViewController.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>toggleTableViewLoading <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span>lastIndexPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSIndexPath</span> indexPathForRow<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>aroundMeArray count<span style="color: #002200;">&#93;</span><span style="color: #002200;">+</span><span style="color: #2400d9;">1</span> inSection<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
    CustomTableViewCell <span style="color: #002200;">*</span>lastCell<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.aroundMeTableView cellForRowAtIndexPath<span style="color: #002200;">:</span>lastIndexPath<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>lastCell toggleLoading<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This method is declared in a delegate which the cell implements.</p>
<p><strong>ActivityDelegate.h</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@protocol</span> ActivityDelegate &lt;NSObject&gt;
    @required
    <span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> toggleLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>showLoading;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>The implementation can be blank.</p>
<p>The custom table cell loaded by your UITableViewController needs to implement this delegate so the UITableView knows is has the toggleLoading method.</p>
<p>In the UITableCell which implements ActivityDelegate, we put the method which shows/hides the indicator. This creates the loading spinner and adds/removes it from the accessoryView in the table cell.</p>
<p><strong>ActivityTableViewCell.m</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> toggleLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>bool<span style="color: #002200;">&#41;</span>showLoading <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>showLoading<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>self.accessoryView setHidden<span style="color: #002200;">:</span><span style="color: #a61390;">true</span><span style="color: #002200;">&#93;</span>;
        isLoading <span style="color: #002200;">=</span> <span style="color: #a61390;">false</span>;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        UIActivityIndicatorView <span style="color: #002200;">*</span>spinner <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActivityIndicatorView alloc<span style="color: #002200;">&#93;</span> initWithActivityIndicatorStyle<span style="color: #002200;">:</span>UIActivityIndicatorViewStyleGray<span style="color: #002200;">&#93;</span>;
        spinner.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">24</span>, <span style="color: #2400d9;">24</span><span style="color: #002200;">&#41;</span>;
        self.accessoryView <span style="color: #002200;">=</span> spinner;
        <span style="color: #002200;">&#91;</span>spinner startAnimating<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>spinner release<span style="color: #002200;">&#93;</span>;
        isLoading <span style="color: #002200;">=</span> <span style="color: #a61390;">true</span>;
        <span style="color: #002200;">&#91;</span>self.backgroundView setNeedsDisplay<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>ActivityTableViewCell.h</strong> declares that is has a loading indicator which can be toggled. Hook this up in Interface Builder.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;ActivityDelegate.h&quot;</span>
<span style="color: #a61390;">@interface</span> ActivityTableViewCell <span style="color: #002200;">:</span> UITableViewCell&lt;ActivityDelegate&gt; <span style="color: #002200;">&#123;</span>
    IBOutlet UIView <span style="color: #002200;">*</span>viwHaveData;
    IBOutlet UIView <span style="color: #002200;">*</span>viwNoData;
    IBOutlet UILabel <span style="color: #002200;">*</span>lblNoData;
    IBOutlet UIActivityIndicatorView <span style="color: #002200;">*</span>loadingIndicator;
    <span style="color: #a61390;">BOOL</span> isLoading;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIView <span style="color: #002200;">*</span>viwHaveData;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIView <span style="color: #002200;">*</span>viwNoData;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UILabel <span style="color: #002200;">*</span>lblNoData;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIActivityIndicatorView <span style="color: #002200;">*</span>loadingIndicator;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, readwrite<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">BOOL</span> isLoading;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>When you need to show the loading spinner, you can call [myCell toggleLoading];</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/10/16/pagination-and-delegates-in-a-uitableview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DevExpress Scheduler: ID of Repeating Appointment</title>
		<link>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/</link>
		<comments>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 17:31:21 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=454</guid>
		<description><![CDATA[Since I started using the DevExpress Scheduler a few weeks back I&#8217;ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments. After hunting around trying every suggested method from DevExpress, I found a support ticket from another developer having the same problem. Using [...]]]></description>
			<content:encoded><![CDATA[<p>Since I started using the DevExpress Scheduler a few weeks back I&#8217;ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments.<br />
<span id="more-454"></span><br />
After hunting around trying every suggested method from DevExpress, I found <a href="http://www.devexpress.com/Support/Center/p/Q261153.aspx">a support ticket from another developer</a> having the same problem.</p>
<p>Using the same kind of method I wrote the following core (pretty horrible) to do the job.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dx:ASPxScheduler</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span>...</span>
<span style="color: #009900;">		...</span>
<span style="color: #009900;">		<span style="color: #000000; font-weight: bold;">&lt;ClientSideEvents</span> <span style="color: #000066;">AppointmentsSelectionChanged</span>=<span style="color: #ff0000;">&quot;function(s, e) { OnAppointmentsSelectionChanged(s, e.appointmentIds);}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dx:ASPxScheduler<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:HiddenField</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;appointmentId&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            function OnAppointmentsSelectionChanged(s, appointmentIds) {
                $('#<span style="color: #009900;">&lt;%= appointmentId.ClientID %<span style="color: #000000; font-weight: bold;">&gt;</span></span>').val(appointmentIds);
            }
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This lets you grab the value from the code-behind (in my case by hooking the <em>ASPxScheduler1_PopupMenuShowing</em> event).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> ASPxScheduler1_PopupMenuShowing<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, PopupMenuShowingEventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        ASPxSchedulerPopupMenu menu <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">Menu</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Check whether an empty cell is clicked rather than an appointment.</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>menu<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>SchedulerMenuItemId<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultMenu</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		var rawSelectedBookingId <span style="color: #008000;">=</span> appointmentId<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// if it's recurring, you get something like 12_0</span>
                var selectedBookingId <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrWhiteSpace</span><span style="color: #008000;">&#40;</span>rawSelectedBookingId<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">:</span> Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToInt32</span><span style="color: #008000;">&#40;</span>rawSelectedBookingId<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><span style="color: #666666;">'_'</span><span style="color: #008000;">&#125;</span>, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveEmptyEntries</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <em>selectedBookingId</em> in my case, is the ID of the database object for the user&#8217;s right click selection</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS App Signing Errors</title>
		<link>http://www.leghumped.com/blog/2011/07/28/ios-app-signing-errors/</link>
		<comments>http://www.leghumped.com/blog/2011/07/28/ios-app-signing-errors/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 08:11:06 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=449</guid>
		<description><![CDATA[For the last day, I&#8217;ve been on the brink of pulling my hair out trying to fix a bizarre error when trying to deploy an app to my iPhone. Everything worked fine in the simulator, but when I tried to deploy it to the device, I kept getting &#8220;The entitlements specified in your application’s Code [...]]]></description>
			<content:encoded><![CDATA[<p>For the last day, I&#8217;ve been on the brink of pulling my hair out trying to fix a bizarre error when trying to deploy an app to my iPhone. Everything worked fine in the simulator, but when I tried to deploy it to the device, I kept getting &#8220;The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.&#8221;</p>
<p><span id="more-449"></span><br />
Suggestions, including <a href="http://www.codza.com/how-to-fix-iphone-code-signing-errors">this post</a> said that cleaning the project, rebuilding, restarting XCode or voodoo incantations had solved it for others, but eventually it turned out to be due to the requirement for an Entitlements file in the project itself. You need to File->New->File, choose iOS->Entitlements File and call it Entitlements.plist, add an entry if one doesn&#8217;t exist for &#8220;Can be debugged&#8221; and set it to true. Now in the settings for the main target in your project, set the code signing entitlements file to the newly created Entitlements.plist file.</p>
<p>Clean, rebuild and launch the app, and hopefully it should work. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/07/28/ios-app-signing-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Geocoding for Zip Code Lookups</title>
		<link>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/</link>
		<comments>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/#comments</comments>
		<pubDate>Sun, 22 May 2011 15:43:50 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=444</guid>
		<description><![CDATA[Forms which need a user&#8217;s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo&#8217;s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add [...]]]></description>
			<content:encoded><![CDATA[<p>Forms which need a user&#8217;s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo&#8217;s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add a click handler. When the button is clicked, an AJAX request is sent to the Yahoo geolocation API via jQuery, the the resulting XML is parsed and the form fields are populated. </p>
<p>This has the benefit of needing just one piece of data (postcode) instead of four. The one problem with this is that the <a href="https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript">same origin policy</a> prevent making AJAX calls to a separate domain. Unfortunately, this means you need an intermediate web service hosted on the same domain as the page which passes on the request. This just needs to return a URL via cURL (PHP) or WebClient (ASP.NET).</p>
<p>Then in JavaScript, the result can be parsed from the returned XML (unfortunately, Yahoo&#8217;s API doesn&#8217;t currently support JSON).<br />
<span id="more-444"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #003366; font-weight: bold;">function</span> addGLookupPostCodeListener<span style="color: #009900;">&#40;</span>searchButtonId<span style="color: #339933;">,</span> postCodeFieldId<span style="color: #339933;">,</span> countryFieldId<span style="color: #339933;">,</span> txtLatitudeId<span style="color: #339933;">,</span> txtLongitudeId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> searchButton <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> searchButtonId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    searchButton.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #003366; font-weight: bold;">var</span> thePostCode <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> postCodeFieldId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>thePostCode <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>
	            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	            $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/API.asmx/LookupPostcode'</span><span style="color: #339933;">,</span>  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'xml'</span><span style="color: #339933;">,</span> data<span style="color: #339933;">:</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> postCode<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color: #009900;">&#40;</span>thePostCode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> response<span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $xml <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $country <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Country&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$country <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// populat country if it exists</span>
	                        haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtCountry <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> countryFieldId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>$country.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	                            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'GB'</span><span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">// the API returns GB as the country code which is no good </span>
	                            txtCountry.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'United Kingdom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
	                            txtCountry.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$country.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $latitude <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Latitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $longitude <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Longitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$latitude <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> $longitude <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// populate lat/long if they exist</span>
	                        haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtLatitude <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> txtLatitudeId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtLongitude <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> txtLongitudeId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        txtLatitude.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$latitude.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        txtLongitude.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$longitude.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>haveNodes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">// if no nodes (due to invalid response or no data), show a message</span>
	                        searchButton.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span class=&quot;block&quot;&gt;Address not found&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                <span style="color: #009900;">&#125;</span>
	            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF: Radio Toggle Button</title>
		<link>http://www.leghumped.com/blog/2011/04/24/441/</link>
		<comments>http://www.leghumped.com/blog/2011/04/24/441/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 20:29:42 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=441</guid>
		<description><![CDATA[There are times when you might want to display a toggle switch to let the user pick between one or more views. The easiest way to implement this in WPF is with RadioButtons and custom templates. Persistence can easily be added by binding to an application settings resource, as in the example below. The first [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when you might want to display a toggle switch to let the user pick between one or more views. The easiest way to implement this in WPF is with RadioButtons and custom templates. Persistence can easily be added by binding to an application settings resource, as in the example below.</p>
<p>The first thing you need is a custom control. This just needs to inherit from RadioButton, I added a few extra properties to make adding images easier.</p>
<p><span id="more-441"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> Lime49<span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// A button which can be assigned an image</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> RadioImageButton <span style="color: #008000;">:</span> RadioButton <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ImageLocationProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ImageLocation&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>PlacementMode<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RadioImageButton<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span>PlacementMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Left</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets the position of the image in relative to the text.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;The image.&lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> PlacementMode ImageLocation <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>PlacementMode<span style="color: #008000;">&#41;</span><span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>ImageLocationProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>ImageLocationProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ImageProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Image&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>ImageSource<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RadioImageButton<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets the image to display.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;The image.&lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> ImageSource Image <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>ImageProperty<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ImageSource<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>ImageProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty TextProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Text&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RadioImageButton<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets the text.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;The text.&lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Text <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>TextProperty<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>TextProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty ShowTextProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ShowText&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RadioImageButton<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">new</span> UIPropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets whether to show the text.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;&lt;c&gt;true&lt;/c&gt; if the text should be shown, otherwise &lt;c&gt;false&lt;/c&gt;.&lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ShowText <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span><span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>ShowTextProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>ShowTextProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> DependencyProperty AlwaysShowBorderProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;AlwaysShowBorder&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RadioImageButton<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets whether to always show the border.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;&lt;c&gt;true&lt;/c&gt; if the border should be shown, otherwise &lt;c&gt;false&lt;/c&gt;.&lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AlwaysShowBorder <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span><span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>AlwaysShowBorderProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>AlwaysShowBorderProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The control template just needs to take these properties and display them. Ie (Visual Statemanager states omitted for brevity):</p>

<div class="wp_syntax"><div class="code"><pre class="xaml" style="font-family:monospace;">&lt;Style TargetType=&quot;{x:Type loc:RadioImageButton}&quot; x:Key=&quot;{x:Type loc:RadioImageButton}&quot;&gt;
        &lt;Setter Property=&quot;Margin&quot; Value=&quot;4,2&quot; /&gt;
        &lt;Setter Property=&quot;ToolTipService.ShowOnDisabled&quot; Value=&quot;True&quot; /&gt;
        &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Stretch&quot; /&gt;
        &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Top&quot; /&gt;
        &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Center&quot; /&gt;
        &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Center&quot; /&gt;
        &lt;Setter Property=&quot;SnapsToDevicePixels&quot; Value=&quot;True&quot; /&gt;
        &lt;Setter Property=&quot;ShowText&quot; Value=&quot;True&quot; /&gt;
        &lt;Setter Property=&quot;ImageLocation&quot; Value=&quot;Top&quot; /&gt;
        &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource NormalForeground}&quot;/&gt;
        &lt;Setter Property=&quot;Background&quot; Value=&quot;{DynamicResource NormalBrush}&quot;/&gt;
        &lt;Setter Property=&quot;BorderBrush&quot; Value=&quot;{DynamicResource NormalBorderBrush}&quot;/&gt;
        &lt;Setter Property=&quot;Template&quot;&gt;
            &lt;Setter.Value&gt;
                &lt;ControlTemplate TargetType=&quot;{x:Type loc:RadioImageButton}&quot;&gt;
                    &lt;Border x:Name=&quot;Border&quot; Padding=&quot;3&quot; BorderBrush=&quot;{TemplateBinding BorderBrush}&quot; Background=&quot;{TemplateBinding Background}&quot;
                        CornerRadius=&quot;1&quot; BorderThickness=&quot;1&quot; ToolTip=&quot;{TemplateBinding ToolTip}&quot; ToolTipService.ShowOnDisabled=&quot;True&quot;&gt;
                        &lt;DockPanel x:Name=&quot;Container&quot; HorizontalAlignment=&quot;{TemplateBinding HorizontalAlignment}&quot; VerticalAlignment=&quot;Center&quot;&gt;
                            &lt;Image x:Name=&quot;PART_img&quot; Source=&quot;{TemplateBinding Image}&quot; Stretch=&quot;None&quot; SnapsToDevicePixels=&quot;True&quot;
                               IsEnabled=&quot;{TemplateBinding IsEnabled}&quot; IsHitTestVisible=&quot;False&quot; /&gt;
                            &lt;TextBlock x:Name=&quot;PART_text&quot; Text=&quot;{TemplateBinding Text}&quot; IsEnabled=&quot;{TemplateBinding IsEnabled}&quot; VerticalAlignment=&quot;{TemplateBinding VerticalContentAlignment}&quot;
                                   TextTrimming=&quot;CharacterEllipsis&quot; TextWrapping=&quot;Wrap&quot; MaxWidth=&quot;{TemplateBinding MaxWidth}&quot; MaxHeight=&quot;{TemplateBinding MaxWidth}&quot;
                                   TextAlignment=&quot;{TemplateBinding HorizontalAlignment}&quot; /&gt;
                            &lt;Grid x:Name=&quot;ValidationErrorElement&quot; Visibility=&quot;Collapsed&quot; ToolTipService.PlacementTarget=&quot;{Binding RelativeSource={RelativeSource TemplatedParent}}&quot;&gt;
                                &lt;ToolTipService.ToolTip&gt;
                                    &lt;ToolTip x:Name=&quot;validationTooltip&quot; 
                                       Template=&quot;{StaticResource ValidationToolTipTemplate}&quot;
                                       DataContext=&quot;{Binding RelativeSource={RelativeSource TemplatedParent}}&quot;
                                       Placement=&quot;Right&quot; 
                                       PlacementTarget=&quot;{Binding RelativeSource={RelativeSource TemplatedParent}}&quot;&gt;
                                        &lt;ToolTip.Triggers&gt;
                                            &lt;EventTrigger RoutedEvent=&quot;Canvas.Loaded&quot;&gt;
                                                &lt;EventTrigger.Actions&gt;
                                                    &lt;BeginStoryboard&gt;
                                                        &lt;Storyboard&gt;
                                                            &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName=&quot;validationTooltip&quot; Storyboard.TargetProperty=&quot;IsHitTestVisible&quot;&gt;
                                                                &lt;DiscreteObjectKeyFrame KeyTime=&quot;0&quot; &gt;
                                                                    &lt;DiscreteObjectKeyFrame.Value&gt;
                                                                        &lt;sys:Boolean&gt;true&lt;/sys:Boolean&gt;
                                                                    &lt;/DiscreteObjectKeyFrame.Value&gt;
                                                                &lt;/DiscreteObjectKeyFrame&gt;
                                                            &lt;/ObjectAnimationUsingKeyFrames&gt;
                                                        &lt;/Storyboard&gt;
                                                    &lt;/BeginStoryboard&gt;
                                                &lt;/EventTrigger.Actions&gt;
                                            &lt;/EventTrigger&gt;
                                        &lt;/ToolTip.Triggers&gt;
                                    &lt;/ToolTip&gt;
                                &lt;/ToolTipService.ToolTip&gt;
                            &lt;/Grid&gt;
                        &lt;/DockPanel&gt;
                    &lt;/Border&gt;
                    &lt;ControlTemplate.Triggers&gt;
                        &lt;Trigger Property=&quot;ImageLocation&quot;&gt;
                            &lt;Trigger.Value&gt;
                                &lt;PlacementMode&gt;Left&lt;/PlacementMode&gt;
                            &lt;/Trigger.Value&gt;
                            &lt;Setter TargetName=&quot;PART_img&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Left&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Right&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;Margin&quot; Value=&quot;2,0,0,0&quot; /&gt;
                        &lt;/Trigger&gt;
                        &lt;Trigger Property=&quot;ImageLocation&quot;&gt;
                            &lt;Trigger.Value&gt;
                                &lt;PlacementMode&gt;Top&lt;/PlacementMode&gt;
                            &lt;/Trigger.Value&gt;
                            &lt;Setter TargetName=&quot;PART_img&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Top&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Bottom&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;Margin&quot; Value=&quot;0,2,0,0&quot; /&gt;
                        &lt;/Trigger&gt;
                        &lt;Trigger Property=&quot;ImageLocation&quot;&gt;
                            &lt;Trigger.Value&gt;
                                &lt;PlacementMode&gt;Right&lt;/PlacementMode&gt;
                            &lt;/Trigger.Value&gt;
                            &lt;Setter TargetName=&quot;PART_img&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Right&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Left&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;Margin&quot; Value=&quot;0,0,2,0&quot; /&gt;
                        &lt;/Trigger&gt;
                        &lt;Trigger Property=&quot;ImageLocation&quot;&gt;
                            &lt;Trigger.Value&gt;
                                &lt;PlacementMode&gt;Bottom&lt;/PlacementMode&gt;
                            &lt;/Trigger.Value&gt;
                            &lt;Setter TargetName=&quot;PART_img&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Bottom&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;DockPanel.Dock&quot; Value=&quot;Top&quot; /&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;Margin&quot; Value=&quot;0,0,0,2&quot; /&gt;
                        &lt;/Trigger&gt;
                        &lt;Trigger Property=&quot;ShowText&quot; Value=&quot;false&quot;&gt;
                            &lt;Setter TargetName=&quot;PART_text&quot; Property=&quot;Visibility&quot; Value=&quot;Collapsed&quot; /&gt;
                        &lt;/Trigger&gt;
                    &lt;/ControlTemplate.Triggers&gt;
                &lt;/ControlTemplate&gt;
            &lt;/Setter.Value&gt;
        &lt;/Setter&gt;
    &lt;/Style&gt;</pre></div></div>

<p>Then in your Window/Page you can use the following to quickly insert a RadioButton which is bound to the AppSettings collection and will persist it&#8217;s state:</p>

<div class="wp_syntax"><div class="code"><pre class="xaml" style="font-family:monospace;">&lt;Window...&gt;
   &lt;Window.Resources&gt;
      &lt;props:Settings x:Key=&quot;Settings&quot; /&gt;
   &lt;/Window.Resources&gt;
   &lt;Grid x:Name=&quot;grdContainer&quot; DataContext=&quot;{StaticResource Settings}&quot;&gt;
       &lt;l49ui:RadioImageButton x:Name=&quot;btnTglRecipes&quot; IsChecked=&quot;{Binding Default.MainWindowDisplayMode,Converter={StaticResource MainWindowDisplayModeConverter},ConverterParameter=Recipes}&quot;
           Image=&quot;pack://application:,,,/Resources/types/burger_24.png&quot; Text=&quot;{lex:LocText ChickenPing.Shared:Strings:Recipes}&quot; Checked=&quot;btnChangeView_Checked&quot; GroupName=&quot;windowdisplay&quot; /&gt;
       &lt;l49ui:RadioImageButton x:Name=&quot;btnTglWines&quot; IsChecked=&quot;{Binding Default.MainWindowDisplayMode,Converter={StaticResource MainWindowDisplayModeConverter},ConverterParameter=Wines}&quot;
           Image=&quot;pack://application:,,,/Resources/images/wine_24.png&quot; Text=&quot;{lex:LocText ChickenPing.Shared:Strings:Wines}&quot; Checked=&quot;btnChangeView_Checked&quot; GroupName=&quot;windowdisplay&quot; /&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> btnChangeView_Checked<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsLoaded<span style="color: #008000;">&#41;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/04/24/441/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

