Displaying a PDF file within a WPF application

I had a need to view PDF files directly within a WPF application and Stackoverflow and Google did not provide much assistance, so I set out on my own to see what I could create.  It turns out, it is not that difficult.  The trick is to use the WinForms support in WPF ala the WindowsFormHost control.  The application is so simple, I built it start to finish in under 5 minutes and captured it in a screencast for you to check out.

WPF PDF viewer app

Read the rest of this entry »

Posted in .NET, Code, WPF. 30 Comments »

WPF MVVM Video by Jason Dolinger

I just happened upon a video put together by Jason Dolinger on the WPF MVVM (Model View ViewModel) pattern, which I found to be excellent.  In this 1.5 hour video he refactors a simple application using the pattern and does a great job describing the benefits as he goes along.  It is also interesting to see his use of Unity as well.  Here is a direct link to the video:

http://www.lab49.com/files/videos/Jason%20Dolinger%20MVVM.wmv

And here’s a link to a blog post about it with a link to the source code:

http://blog.lab49.com/archives/2650

Enjoy!

Posted in .NET, MVVM, WPF. 2 Comments »

Intro to WPF MVVM

Last week, I gave a presentation at the Madison .NET User Group on an introduction to the up-and-coming Model-View-View Model (MVVM) pattern for WPF.

mvvm-overview

In the presentation, we made a very simple application that used the MVVM pattern.  I’ve posted the source code to this quick and dirty app here.  Note: this app takes several shortcuts and shouldn’t be used as an example of best practices, but we did build it in about 30 minutes.  :)

Read the rest of this entry »

Getting Started in WPF with IValueConverter

For those of you looking to learn or hone your fundamental WPF skills, I thought you might find this video beneficial.  It’s a nice 11-12 minute video on what you can do with IValueConverter by the lovely Beth Massi.   The video goes through an example of IValueConverter in VB.NET, but they also have some C# code to download if you like.  Check it out:

http://msdn.microsoft.com/en-us/vbasic/dd367843.aspx

The IValueConverter interface is very handy when you want to convert or format a given object to your specifications, and in Beth’s example she also displays how you can use it to verify and do type validation of user edited data.

Microsoft StyleCop

I just found out about a C# source code analysis tool from Microsoft called StyleCop.  You can download it from code.microsoft.com.

The tool’s description is as follows:

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project.

For all the details on the tool, check out the team’s blog that wrote it at http://blogs.msdn.com/sourceanalysis/.

Smart Paster Add-In for Visual Studio 2008

I had the need today to take a bunch of JavaScript code and paste it into an ASP.NET code behind file.  I was using the script as a basis for a custom script that was placed into the Page using the ClientScript.RegisterClientScriptBlock method.  I did some quick googling and found the Visual Studio Add-In called Smart Paster from Alex Papadimoulis that was just what I was looking for.  It wasn’t supplied in compiled form, but it was easy to build and deploy.  Just open the solution file, compile for Release mode and then copy the two files (from the bin folder) into your Addins folder:

  • SmartPaster2008.AddIn
  • SmartPaster2008.dll

Note: Your Addins folder is located by default at C:\Users\<username>\Documents\Visual Studio 2008\Addins

Simply restart VS2008 and now check out the new Right Click “Paste As” menu option:

smart-paster-example

There are some options via the Configure menu item too.  Very handy!

LINQ to iTunes

I lost a hard drive a few weeks ago, and with it my up-to-date MP3 collection.smile_sad Luckily I had a backup of most of the MP3′s, but I wanted to find out exactly which MP3′s I had recovered and which ones I was missing. I knew the iTunes library is stored in an XML formatted file, but I would need to write something to read it and extract out the filenames of the individual MP3 files and then verify if they existed.

I have been using LINQ quite a bit lately on various projects, but only LINQ to SQL. I knew of LINQ to XML, but now I had a real reason to learn it.

First I looked at the iTunes library format. Here’s a snippet of the beginning of my file:

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Major Version</key><integer>1</integer>
    <key>Minor Version</key><integer>1</integer>
    <key>Application Version</key><string>7.6.2</string>
    <key>Features</key><integer>5</integer>
    <key>Show Content Ratings</key>
<true />
    <key>Music Folder</key><string>file://localhost/C:/Documents%20and%20Settings/chujanen/My%20Documents/My%20Music/iTunes/iTunes%20Music/</string>
    <key>Library Persistent ID</key><string>54F22391EB807F23</string>
    <key>Tracks</key>
    </dict><dict>
        <key>1666</key>
        </dict><dict>
            <key>Track ID</key><integer>1666</integer>
            <key>Name</key><string>What's the Matter Here?</string>
            <key>Artist</key><string>10,000 Maniacs</string>
            <key>Album Artist</key><string>10,000 Maniacs</string>
            <key>Composer</key><string>Natalie Merchant/Robert Buck</string>
            <key>Album</key><string>In My Tribe</string>
            <key>Genre</key><string>Rock</string>
            <key>Kind</key><string>MPEG audio file</string>
            <key>Size</key><integer>9318485</integer>
            <key>Total Time</key><integer>291134</integer>
            <key>Track Number</key><integer>1</integer>
            <key>Year</key><integer>1987</integer>
            <key>Date Modified</key><date>2005-03-09T07:31:09Z</date>
            <key>Date Added</key><date>2007-07-20T17:21:36Z</date>
            <key>Bit Rate</key><integer>256</integer>
            <key>Sample Rate</key><integer>44100</integer>
            <key>Comments</key><string></string>
            <key>Persistent ID</key><string>54F22391EB807F38</string>
            <key>Track Type</key><string>File</string>
            key>Location<string>file://localhost/S:/mp3/10,000%20Maniacs/In%20My%20Tribe/01%20-%20What's%20the%20Matter%20Here%20.mp3</string>
            <key>File Folder Count</key><integer>-1</integer>
            <key>Library Folder Count</key><integer>-1</integer>
        </dict>
        <key>1667</key>
        <dict>
            <key>Track ID</key><integer>1667</integer>
            <key>Name</key><string>Hey Jack Kerouac</string>
            <key>Artist</key><string>10,000 Maniacs</string>

Read the rest of this entry »
Posted in .NET, Code. 5 Comments »
Follow

Get every new post delivered to your Inbox.