WPF Master Pages (kinda sorta)

I decided to build a simple project management application in my quest to wrap my head around WPF.  So far I set up the database, got an Entity Framework model happily binding, and started writing CRUD “pages” (the TabItems of a TabControl as shown in the GUI shown).

image

These pages share much of the same presentation and logic and, after writing two of them, I knew I had to refactor them somehow.  Some kind of “master page” would work well here.  I will just define the entity-specific controls and the data calls for each page and the rest of the presentation and logic will live in non-repeated harmony in the master page.

Well, my first idea, subclassing a XAML-based UserControl turns out to be very tricky to get by the compiler and generally a bad idea.

These links provide some valid ways to implement master page type functionality in WPF:

I’ll share some code later once I am happy with my implementation.  One issue is that you can’t bind between controls in different ContentControls (as noted in this comment), which I need for this application.  I know there has to be a better way…

All I want to do is copy some files!!

I just have to blog this so I can help anybody else in this situation (including myself next time I need it).

I was trying to recover data from a friend’s computer with a sick hard drive. I couldn’t boot into Windows due to some poorly placed bad sectors so I booted using a very handy Linux rescue CD called Trinity Rescue Kit. This worked great. I got on my network, mounted the Windows drives, and ran the ‘fileserver -s’ command to auto-share the drives to Windows via SMB.

image

Everything is cruising along…

The Problem

I want to be able to easily copy specific folders and files (sometimes entire folder trees) across three different target (sick) drives to my local drive.

I don’t want to have to ctrl-select a hundred different folders or copy them one at a time and have to wait between copies. I want to be able to easily filter folders beforehand and copy them all at once. I am positive this is easier than I made it, but I embarrassingly banged my head for a couple of hours with these tools:

  • XCOPY - You can exclude folders, but it’s painful, deprecated, and I want a GUI.
  • robocopy - Powerful, kind of a pain to get in XP (comes standard in Vista), and has a basic GUI. It still is cumbersome if you want to do a one-time selective copy of a bunch of folders.
  • XXCOPY - A super-XCOPY. Tons of options and just over-complex for one-time use. No GUI that I could find.
  • Beyond Compare - This is a fantastic diff tool and is actually mentioned in a few places as a potential answer to this problem. You can exclude files through a relatively intuitive interface, but there is one big problem once you start the copy. Summed in in their documentation: If a folder is selected, its entire contents are copied, regardless of file filters or display filters in effect. So, no good for what I need.
  • Various other shareware-type apps - It would just confuse things more to link to them here.
  • Write my own - This was one of those problems where I thought about starting Visual Studio the entire time but I always thought I was going to find the solution any second. Luckily, I found something that kind of worked.

The Solution

I’ve used Backup4all before backup purposes but it didn’t occur to me to try it for one-time copies. I don’t think there is a free version, but it’s cheap and does its job very well (it at least has a free 30-day trial). The secret is to use “mirror” mode which means it just copies and doesn’t try to compress or anything.

image

The workflow is exactly what I wanted. At it’s simplest (it has a lot more options), you choose the folders in a treeview (this works for network or local locations):

image

Then add any global include or exclude filters:

image

Then select a destination:

image

Then hit the Backup button:

image

And the filtered list of files is copied! Such a simple problem to not be able to solve easier. Hopefully this post will help.

Please comment if you’ve found a better way to do this.

Exercise While Playing XBox ?

No, this isn’t a DDR post, but it’s close. :)

During my regular blast through Lifehacker posts a few weeks ago, this post called Burn 600 Calories a Day Typing (source) caught my eye. Long story short, Jonathan Fields built a fancy keyboard for his treadmill and he walks slowly all morning long. Very cool idea!

Then, I saw a comment in the Lifehacker post about somebody who rides his recumbent bike while playing XBox. That tripped a familiar synapse in my brain that makes me start buying things and waste time that I don’t have (watch this space for lots more like this one).

See, I have very low willpower when it comes to exercise. I’ve tried various different inspirational techniques, but none ever stick (as has everybody I assume). But… could playing XBox while exercising distract my mind so much that it forgets it is exercising (what I’m calling the Critical Distraction Point)? Through the first two weeks of this experiment, the answer is a solid Yes.

image

My Setup

If you are inspired enough to try this out, you’ll need a stationary recumbent bike. The reason is that with a recumbent bike only your legs move and your upper body is stable. I bought this one from Amazon for just over $200 (and free shipping since I have Prime). Here’s a mini-review, Good: It’s super quiet and perfect for my use. The LCD display is low (physically) so it doesn’t obstruct straight-ahead viewing. Bad: The LCD and programs are certainly not gym quality, but I don’t really plan to use those anyway. Here are some pics of my setup:

bike1

With a bit of side turning you can do a bit of laptop work. Hard to have a laptop in front of you without hitting your knees. BTW, that’s the multi-tasking Dave laptop stand from IKEA also mentioned on Lifehacker (source and IKEA link) (yes, I’m easily influenced).

bike2

As you can see, the LCD is not why you’d buy this. It does count time well though which is all I need.

Summary

If you’re looking for a great way to trick yourself into exercising (and who isn’t!) I highly recommend this method. Until I burn out on it in a few weeks of course. :)

Getting Started with WPF

image

I don’t know about you, but it seems more difficult to get started with Windows Presentation Foundation (WPF) than it should be. I’ve been dabbling with it for a while, but I recently wanted to build a client-side application to track my ongoing projects and decided to resist the temptation to pump out another Windows Forms app and use the experience to get familiar with WPF.

This post is my recommendation on the best way I’ve found to ramp up on WPF.

I’ll likely make a few of these posts as I continue to find valuable resources. One thing I want to do is make a simple screencast that shows how to make a standard business-style application. With all the whiz-bang things WPF can do, it seems that real-world examples are hard to find. I’m less concerned with the sexy graphics aspects (animation, gradients, etc.) and more with the fact that Microsoft is putting all of its resources behind this and my bet is most new client-side GUI innovations (controls, tools, patterns, third party support) will happen here, not in WinForms.

Who are these posts for?

It will help if you are exactly like me! :) Who is that?

I’m starting from a strong background in .NET. By that I mean all technologies considered part of .NET 2.0. I have dabbled with the 3.0 technologies (WCF, WPF, LINQ, WF, etc.) but I am still ramping up on those. This means I have a good working knowledge of XML (which is a considerable help with WPF where most tools don’t talk code — they talk XAML).

I’m not a creative-type person. There is no doubt that designers love WPF and the designer-coder workflow is much better than it was before, but I won’t concentrate on design here. Also, “user experience” is a big part of WPF, but I’m just not approaching it from that angle yet.

Also, I tend to learn better by video, screencasts, and real code rather than articles. So, the resources below are weighted towards non-text.

Basics

  • WPF is the new (well, 2 or 3 year old) client-side development story for .NET. Windows Forms still exists, but from what I’ve seen any new development should strongly consider switching to WPF (see above). There are a few things missing that we have in Windows Forms (like a DataGrid/GridView) but those and much more are on their way (see this video from MIX08 for upcoming improvements).
  • WPF takes full advantage of Microsoft’s new way to express .NET code in XML. It’s called XAML (here is an overview that is worth a glance but the resources below are better).
  • Most of these resources assume you have installed (at a minimum) .NET Framework 3.5. Download and install here.

Great Resources (How To Learn It)

This is my version of the most efficient path for learning WPF. After these you will have a good understanding of how WPF works and some great examples to explore.

  • If you’re at all serious, go ahead and buy WPF Unleashed by Adam Nathan. Don’t really read it end-to-end, but you will reference it constantly while using the other resources here. It is very well done. Read the Amazon reviews for more praise. Chris Sells and Ian Griffith’s book is also good, but not as clear in my opinion.
  • I would start with these fantastic WPF Bootcamp videos (actually, the ones here are newer versions of the same material although I haven’t seen them yet — see Karsten’s blog entry below for a individual download links). Watch the first three videos (the keynote, lap around WPF, and lap around Blend) to get an overview of what WPF is all about. By all means, watch these on high speed (see the first sentence in this post for how to speed up videos — I couldn’t easily get the embedded versions to speed up so download them if you want to speed them up).
  • This post by jfo is a bit dated, but I found the attached Word document “WPF for those who know Windows Forms” to be a real gem (direct download link). It has information that I haven’t found aggregated anywhere else. Check the other links on that page, but that article is the great resource even if you aren’t coming from Windows Forms.
  • Watch the next two Bootcamp training videos by Ian Griffiths (or the equivalents in the newer videos). Really, really good. These will give you a solid base while whetting your appetite for some intermediate WPF functionality.
  • Kevin Moore’s Bag-o-Tricks (here) is bite-sized chunks of super cool WPF functionality. Tear into it, check out the code, and see how it works.
  • The Mix08 videos are largely for designers and the presentation layer. I haven’t seen any I would expressly recommend, but there is a lot of content here.

Other Resources

Most of these are highly recommended but they didn’t appeal to me like the Great Resources above.

Tools

Here are some tools that fill in the some gaps left by Visual Studio 2008 and WPF.

  • Microsoft Expression Blend - Awesome tool to develop WPF interfaces. It “blends” seamlessly with Visual Studio 2008 and makes design-time easier (general interface, animation, and lots more). It’s not free, but you can download the preview and beta versions for free. The latest as of now is the 2.5 March Preview (download here). Here’s some fantastic training videos for those interested in the design aspects of Blend.
  • XAMLPad (also see Kaxaml below) - A lightweight XAML editor where you can immediately see the results of your XAML. Kind of a sandbox for XAML like SnippetCompiler is for code. It comes as part of the Windows SDK. In my installation it can be found at C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin .
  • Kaxaml - This is easier to install and has many more features than XAMLPad, but you might want XAMLPad anyway to follow most of the examples on the Web.
  • Snoop - Visually debug and inspect WPF applications at runtime (Spy++ for WPF).
  • Xceed DataGrid for WPF - Until Microsoft makes a DataGrid control you are stuck building your own out of a ListView in GridView mode, borrowing the WinForms grid (yuck), or using a third party grid. Xceed’s grid works well and the express edition is free within some boundaries. Infragistics has one too but I usually have bad experiences with their controls and there is no free version that I can see (disclaimer: I have not tried the Infragistics grid).

Blogs

There are a ton of WPF blogs, but these few are relatively active and have been the most helpful to me so far. Warning: once you start reading these blogs you are on your way down a slippery slope into WPF mastery that will eat up all your time. :)

  • Scott Guthrie - Microsoft head of .NET development, so this is the source of it all.
  • Josh Smith - Great teaching style on a wide range of WPF subjects.
  • Kevin Moore - The Bag-o-Tricks mentioned above and other insightful posts.
  • Ian Griffiths - Great in-depth .NET articles (not all WPF).
  • Dr. WPF - Lots of great info. No offense to the Dr, but the formatting and layout is a bit rough. I prefer to read this one in my RSS reader.
  • Karsten Januszewski - WPF training info but also a good source of WPF news and events. Check here for the 2008 Bootcamp videos and information that I mentioned above.

At this point you should have a ton of other resources to check out. WPF is huge and there is a lot to learn, but these resources should give you a solid start with WPF. Comment below if you have found anything else remarkable.

I also wanted to point out this other Getting Started post by Karsten. I really like the content but it is getting stale and the links are breaking.

Time stretching MP3 and other audio

Want to listen to that 8 hour audio book in 6 hours and not lose any details in the process?

I love Windows Media Player’s ability to speed up or slow down audio and video in real-time via its awesome Play Speed setting. This is commonly referred to as time stretching or changing tempo. If you listen to a lot of podcasts and audio books or watch a lot of instructional videos (like I do) this can save hours and hours in the long run.

The problem is that I like to listen to podcasts or audio books in the car, and I don’t have a fancy PC available to speed audio up in real-time. My Sansa e250 with Rockbox does lots of cool things, but alas it can’t speed up audio without the dreaded chipmunk effect.

I looked for a way to easily (and cheaply) time stretch my audio files, but mostly found a bunch of headaches. There are painful ways to do it with Audacity (open, apply filter, convert, save, etc.) and other audio editors. I think there’s a way to do it through WinAmp. There are also programs made to specifically convert audio like dbPoweramp, but I didn’t have much luck with that (and it’s not free).

My Solution

Here’s the best solution I’ve found so far (and I looked long and hard). It’s easy to setup and has worked super fantastically so far:

foobar2000 + SoundTouch DSP plug-in

1. Download and install foobar2000.

2. Download foo_dsp_soundtouch.dll from wherever you can find it (I got mine from here). This thing was a pain to find. You might also need the vc8 runtime files. They are included in the .NET runtime so might as well download and install that. Copy foo_dsp_soundtouch.dll to your foobar2000 components folder.

image

3. Drop an audio file (or a bunch of audio files) into foobar2000 (or use File -> Open). I’ll use an episode of the excellent Hanselminutes podcast as an example.

image

4. Choose a Convert option from the right-click context menu and set your encoding options (the ones in these pics work well for me).

image

image

5. Click OK and watch it churn out your sped up mp3(s).

Tips and Thoughts

I’ve been using 25% speed-up on audio books and informational podcasts and 12.5% on entertainment-related podcasts like Dawn and Drew. At 25% it’s easily listenable but you can really tell it’s sped up. At 12.5% you can really only tell if you listen to the original along side it. Also, I feel like I concentrate and pick up more (kind of a “flow” thing) when it is sped up.

Being able to drag and drop a bunch of files, right click once, and watch all the converted mp3s pop out is an amazing efficiency over some of the other methods I found.

So, let me know if you’ve found alternate solutions or can improve on this one (I haven’t tweaked many of the settings). And if you want to start looking forward to that hour-long drive to work in the morning, buy a cheap mp3 player and check some of these podcasts out.

So, this is my blog…

imageHello, World!  My name is Blake and I want to share things with you.  No, not those kinds of things.  Nice things.  Like knowledge.  I consider myself an accidental learner which means I stumble though information at various levels of efficiency and absorb stuff as I go.  That results in a lot of breadth without a lot of depth which is due to a bit of ADD and is sometimes a dangerous thing. :)

Professionally, I am employed by a company named TopCoder.  You might know them from their algorithm programming competitions (if you know C#, VB.NET, C++, or Java, I highly recommend them — super fun).  My work is on the software side of things.  We build enterprise software for customers using competitions through our member base.  I’m a project manager (sometimes architect) and have various responsibilities including launching some exciting and lucrative software design and development competitions.  I won’t talk about that much in this blog but comment if you are interested.

For fun, I’m mostly a nerd.  I do the normal geek stuff - read a lot of blogs, write a bunch of code (.NET mostly), and read a lot of books.  I also play some golf (not as much as I’d like) and watch some sports (again, not as much as I’d like). 

So, expect tech, sports, possibly a bit of politics, and whatever else is on my mind.

Welcome!