<?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>Digital Moose Tracks &#187; WPF</title>
	<atom:link href="http://digitalmoosetracks.com/blog/tag/wpf/feed" rel="self" type="application/rss+xml" />
	<link>http://digitalmoosetracks.com/blog</link>
	<description>.Net, MythTV and Me</description>
	<lastBuildDate>Mon, 08 Mar 2010 06:24:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>I love DataTemplates</title>
		<link>http://digitalmoosetracks.com/blog/i-love-datatemplates</link>
		<comments>http://digitalmoosetracks.com/blog/i-love-datatemplates#comments</comments>
		<pubDate>Tue, 18 Aug 2009 21:43:23 +0000</pubDate>
		<dc:creator>joshua</dc:creator>
				<category><![CDATA[Programing]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://digitalmoosetracks.com/blog/i-love-datatemplates</guid>
		<description><![CDATA[I have been playing around with WPF and  started writing a little game to experiment with.   So far I think my favorite thing about WPF has been data templates.  I defined a data template for a Gem Card, one of the game pieces. &#60;DataTemplate DataType="{x:Type game:GemCard}"&#62; &#60;Border Style="{DynamicResource CardBorder}" Background="Green"&#62; &#60;Border Style="{DynamicResource CardHighlight}"&#62; &#60;Grid&#62; &#60;Label [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with WPF and  started writing a little game to experiment with.   So far I think my favorite thing about WPF has been data templates.  I defined a data template for a Gem Card, one of the game pieces.</p>
<pre class="brush: xml;">&lt;DataTemplate DataType="{x:Type game:GemCard}"&gt;
    &lt;Border Style="{DynamicResource CardBorder}" Background="Green"&gt;
    &lt;Border Style="{DynamicResource CardHighlight}"&gt;
        &lt;Grid&gt;
            &lt;Label Content="{Binding Value}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" FontSize="18.667"/&gt;
            &lt;Label Content="{Binding Value}" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" FontSize="18.667"/&gt;
            &lt;Path Stretch="Fill" Stroke="Black" Data="m0,0 l1,1 -1,1 -1,-1z" Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Center" Width="40" Height="60"/&gt;
            &lt;Label Content="{Binding Gems}" FontSize="18.667" HorizontalAlignment="Center" VerticalAlignment="Center"/&gt;
        &lt;/Grid&gt;
    &lt;/Border&gt;
    &lt;/Border&gt;
&lt;/DataTemplate&gt;</pre>
<p>And when I put a GemCard in a content control in my game it looks something like this</p>
<p><a href="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/08/image.png"><img style="border: 0pt none; display: inline;" title="image" src="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/08/image_thumb.png" border="0" alt="image" /></a></p>
<p>I like this approach a lot because I can just tell WPF how I want my classes to be presented and then I can just start putting them in listboxes with out having to worry about how the will look.</p>
]]></content:encoded>
			<wfw:commentRss>http://digitalmoosetracks.com/blog/i-love-datatemplates/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPF Transparent Window With Resizing</title>
		<link>http://digitalmoosetracks.com/blog/wpf-transparent-window-with-resizing</link>
		<comments>http://digitalmoosetracks.com/blog/wpf-transparent-window-with-resizing#comments</comments>
		<pubDate>Fri, 17 Jul 2009 19:51:41 +0000</pubDate>
		<dc:creator>joshua</dc:creator>
				<category><![CDATA[Programing]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://digitalmoosetracks.com/blog/?p=76</guid>
		<description><![CDATA[When I was playing with the FlicScannerWedge Clone I wrote I decided I wanted to make the window look like a barcode cause that would be cool looking.  Plus hey its WPF so it should be able to do something like this. So I found this cool looking image to use as the window background. [...]]]></description>
			<content:encoded><![CDATA[<p>When I was playing with the FlicScannerWedge Clone I wrote I decided I wanted to make the window look like a barcode cause that would be cool looking.  Plus hey its WPF so it should be able to do something like this. So I found this cool looking image to use as the window background.</p>
<p><a href="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/Barcode.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Barcode" src="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/Barcode_thumb.png" border="0" alt="Barcode" width="260" height="189" /></a></p>
<p>So I set it as the background and make the window style none and allow transparency and I get the following</p>
<p><a href="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/image_thumb3.png" border="0" alt="image" width="244" height="165" /></a></p>
<p>Bamm!! I was pretty excite that it was so easy but then I went to resize the window and no joy <img src='http://digitalmoosetracks.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .  So I ask Google how to handle this and find Kirupa Chinnathambi’s <a href="http://blog.kirupa.com/">blog</a> where he shows you how to do this.  The way his example works is by creating a bunch of transparent ‘handles’ around they boarder of your window and then handling some mouse events to do the resizing.  Here’s how my window looks with the handles colored in.</p>
<p><a href="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/image_thumb4.png" border="0" alt="image" width="244" height="165" /></a></p>
<p>So I go through the steps and it resizing and am happy.  Since Kipupa’s was presented more as a proof of concept I pulled out the resizing logic into a base class and did a little refactoring.  The refactoring I liked the most was using Enum,Parse and a dictionary  to replace a switch statement. Turning this</p>
<pre class="brush: csharp;">private void Resize(object sender, MouseEventArgs e)
{
    Rectangle clickedRectangle = sender as Rectangle;
    ResizeDirection direction = ResizeDirection.Top;

    switch (clickedRectangle.Name)
    {
        case "top":
            this.Cursor = Cursors.SizeNS;
            direction = ResizeDirection.Top;
            break;
        case "bottom":
            this.Cursor = Cursors.SizeNS;
            direction = ResizeDirection.Bottom;
            break;
        case "left":
            this.Cursor = Cursors.SizeWE;
            direction = ResizeDirection.Left;
            break;
        case "right":
            this.Cursor = Cursors.SizeWE;
            direction = ResizeDirection.Right;
            break;
        case "topLeft":
            this.Cursor = Cursors.SizeNWSE;
            direction = ResizeDirection.TopLeft;
            break;
        case "topRight":
            this.Cursor = Cursors.SizeNESW;
            direction = ResizeDirection.TopRight;
            break;
        case "bottomLeft":
            this.Cursor = Cursors.SizeNESW;
            direction = ResizeDirection.BottomLeft;
            break;
        case "bottomRight":
            this.Cursor = Cursors.SizeNWSE;
            direction = ResizeDirection.BottomRight;
            break;
        default:
            break;
    }

    if (e.LeftButton == MouseButtonState.Pressed)
        ResizeWindow(direction);
}</pre>
<p>in to this</p>
<pre class="brush: csharp;">private Dictionary&lt;ResizeDirection, Cursor&gt; cursors = new Dictionary&lt;ResizeDirection, Cursor&gt;
{
    {ResizeDirection.Top, Cursors.SizeNS},
    {ResizeDirection.Bottom, Cursors.SizeNS},
    {ResizeDirection.Left, Cursors.SizeWE},
    {ResizeDirection.Right, Cursors.SizeWE},
    {ResizeDirection.TopLeft, Cursors.SizeNWSE},
    {ResizeDirection.BottomRight, Cursors.SizeNWSE},
    {ResizeDirection.TopRight, Cursors.SizeNESW},
    {ResizeDirection.BottomLeft, Cursors.SizeNESW}
};

private static ResizeDirection GetDirectionFromName(string name)
{
    //Hack - Assumes the drag handels are all named *DragHandle
    string enumName = name.Replace("DragHandle", "");
    return (ResizeDirection)Enum.Parse(typeof(ResizeDirection), enumName);
}

protected void ResizeIfPressed(object sender, MouseEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;
    ResizeDirection direction = GetDirectionFromName(element.Name);

    this.Cursor = cursors[direction];

    if (e.LeftButton == MouseButtonState.Pressed)
        ResizeWindow(direction);
}</pre>
<p>Which is a little smaller and more readable IMHO – although probably slower. Here is the source.</p>
<p><a href="http://digitalmoosetracks.com/blog/wp-content/uploads/2009/07/FlicScannerWedge.zip">Flic Scanner Wedge Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://digitalmoosetracks.com/blog/wpf-transparent-window-with-resizing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

