Tech Tock

Time is of the essence.

Reading like its 2009

WPF Control Development Unleashed: Building Advanced User Experiences

I’m reading fellow Lab49er Pavan Podilla’s book:

WPF Control Development Unleashed:
Building Advanced User Experiences

It has some nice advanced examples like the circular minute timer. You can get the book’s great demo app with code here.  Anybody working in WPF should read this book.

Here’s the Circular Minute Timer:

This demo has an interesting resizing issue:

When the window width is reduced, the Arc, which is a subclass of Shape, doesn’t resize.  Resizing is fine for increasing the height or width, or decreasing the height.  Its only decreasing the width that causes a problem.  The problem is that WPF respects the width of the Geometry and doesn’t force it to resize and since the arc starts drawing on the right side it never allows a smaller width to take effect.

I made a simple fix by having the Arc size itself the same as another control:

Code Snippet
  1. <Ellipse
  2.         StrokeThickness=”30″
  3.                 Margin=”5″
  4.         x:Name=”SizeGuide”
  5.                 />
  6. <Runner:Arc StrokeThickness=”30″
  7.             Stroke=”{TemplateBinding BorderBrush}
  8.             Margin=”5″
  9.            SizeGuide=”{Binding ElementName=SizeGuide}
  10.            >

The Ellipse named SizeGuide will automatically size itself and the Arc can use the ellipse actual height and width to size its own geometry:

Code Snippet
  1. doubleSizeWidth
  2. {
  3.     get
  4.     {
  5.         returnthis.SizeGuide == null ? this.RenderSize.Width : this.SizeGuide.ActualWidth;
  6.     }
  7. }
  8. doubleSizeHeight
  9. {
  10.     get
  11.     {
  12.         returnthis.SizeGuide == null ? this.RenderSize.Height : this.SizeGuide.ActualHeight;
  13.     }
  14. }
  15. privatePointPointAtAngle(doubleangle)
  16. {
  17.     doubleradAngle = angle * (Math.PI / 180);
  18.     doublexRadius = (this.SizeWidthStrokeThickness) / 2;
  19.     doubleyRadius = (this.SizeHeightStrokeThickness) / 2;

So, the resize works now:

About these ads

January 3, 2013 - Posted by | Uncategorized |

1 Comment »

  1. I read that one a few years back – a strong focus on attached properties, and a nice intro to pixel shaders. Sadly, WPF has stagnated since then.

    Comment by Josh Reuben | January 3, 2013 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: