Monthly Archives: June 2009

Pin Outlook Templates to the Taskbar for Quick Access [Outlook Tip]

Reader Stephen writes in with an excellent, time-saving Windows 7 tip: you can create Outlook templates for boilerplate emails and pin them to the Windows taskbar for easy access.

This technique is not limited to readers using Windows 7, since you can pin a folder to the taskbar in any version of Windows—but the new Jump lists in Windows 7 make it a lot simpler. To create your own set of Outlook templates, Stephen advises:

  1. Create an Outlook template by composing a new email message with the text you want, and then using File -> Save As to save the message as an Outlook Template into a folder of your choice.
  2. If you are using Windows 7, simply drag the template files onto the Outlook icon.
  3. For previous versions of Windows, right-click the taskbar, choose Toolbars -> New Toolbar, and pick the folder that you saved the templates into.
  4. Now you can quickly access your templates from the Jumplist by right-clicking on the Outlook icon. For previous versions of Windows, you can use the pop-up folder menu.

It’s a great tip for anybody that repeatedly sends emails on the exact same topic. Thanks, Stephen!

For more ways to be productive while dealing with email overload, learn how to save time and typing with Outlook 2007′s Quick Parts, tweak Outlook to empty your inbox faster, knock down repetitive email with AutoHotkey, or just take a look through our top ten Outlook boosters.





Handling Events within Silverlight Control Templates – AutoCompleteBox Example

One of the great features Silverlight offers is the ability to customize controls by using control templates.  If you don’t like how a particular control looks you can modify the template and in many cases be ready to use the new control without writing a single line of C# or VB code.  I’m working on a client application that uses the AutoCompleteBox found in the Silverlight Toolkit and needed a way to change it from a regular TextBox to more of an editable ComboBox.  Fortunately the Silverlight Toolkit samples (for Silverlight 2 and 3) already do something like this as you can see here (once on the page click on AutoCompleteBox to the left and then on the Styling tab at the top of the page to see the sample).

image

The sample modifies the standard AutoCompleteBox to look more like an editable ComboBox by defining a custom control template with a ToggleButton in it (Tim Heuer provides a nice walk through of this type of customization here if you’re interested).  Here’s a simplified version of the Silverlight Toolkit’s sample template that I’m using:

<ControlTemplate TargetType="input:AutoCompleteBox">     <Grid Margin="{TemplateBinding Padding}">         <TextBox IsTabStop="True" x:Name="Text" Style="{TemplateBinding TextBoxStyle}" Margin="0" />         <ToggleButton x:Name="ToggleButton"             HorizontalAlignment="Right"             VerticalAlignment="Center"             Style="{StaticResource ComboToggleButton}"             Margin="0"             HorizontalContentAlignment="Center"              Background="{TemplateBinding Background}"              BorderThickness="0"              Height="16" Width="16"             Click="DropDownToggle_Click">             <ToggleButton.Content>                 <Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z "                        Margin="0,0,6,0" HorizontalAlignment="Right">                     <Path.Fill>                         <SolidColorBrush x:Name="BtnArrowColor" Color="#FF333333"/>                     </Path.Fill>                 </Path>             </ToggleButton.Content>         </ToggleButton>         <Popup x:Name="Popup">             <Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Opacity="1.0" BorderThickness="0">                 <Border.RenderTransform>                     <TranslateTransform X="2" Y="2" />                 </Border.RenderTransform>                 <Border.Background>                     <SolidColorBrush Color="#11000000" />                 </Border.Background>                         <ListBox x:Name="Selector" ScrollViewer.HorizontalScrollBarVisibility="Auto"                               ScrollViewer.VerticalScrollBarVisibility="Auto"                               ItemTemplate="{TemplateBinding ItemTemplate}" />              </Border>         </Popup>     </Grid> </ControlTemplate>


Looking at the template you’ll see that it defines a ToggleButton with a Click event and associated event handler named DropDownToggle_Click.  Here’s what the ToggleButton’s Click event handler looks like:

private void DropDownToggle_Click(object sender, RoutedEventArgs e) {     FrameworkElement fe = sender as FrameworkElement;     AutoCompleteBox acb = null;     while (fe != null && acb == null)     {         fe = VisualTreeHelper.GetParent(fe) as FrameworkElement;         acb = fe as AutoCompleteBox;     }     if (acb != null)     {         if (String.IsNullOrEmpty(acb.SearchText))         {             acb.Text = String.Empty;         }         acb.IsDropDownOpen = !acb.IsDropDownOpen;     } }


You can see that the code uses the VisualTreeHelper class to access the parent of the ToggleButton which is the AutoCompleteBox.  Once the AutoCompleteBox parent is found the code handles showing or hiding the Popup control that’s part of the control template by setting the IsDropDownOpen property to true or false.

This works fine if the control template is placed in the same scope as the event handler code such as the page or user control resources section.  However, if you try to move the template code to another resources section that doesn’t have access to the event handler code (DropDownToggle_Click) you’ll run into problems .  What if you want to put the control template in a merged resource dictionary (similar to an external CSS stylesheet to give a web analogy) and can’t hard-code the click event into the control template since you don’t know where the event handler will be defined at that point?  Although you can certainly write a custom control that derives from AutoCompleteBox in this case (which would be recommended if you’ll re-use the control across multiple pages or user controls), another solution is to hook-up the ToggleButton’s Click event when the AutoCompleteBox control first loads as shown next:

 

void SilverlightApplication_Loaded(object sender, RoutedEventArgs e) {     HookAutoCompleteBoxEvents(); }  void HookAutoCompleteBoxEvents() {     AutoCompleteBox[] boxes = { this.JobIDAutoCompleteBox, this.EmployeeAutoCompleteBox };     foreach (var box in boxes)     {         Grid grid = VisualTreeHelper.GetChild(box, 0) as Grid;         ToggleButton tb = grid.Children[1] as ToggleButton;         if (tb != null) tb.Click += DropDownToggle_Click;     } }


When the Silverlight application Loaded event is called it calls the HookAutoCompleteBoxEvents() method.  Within HookAutoCompleteBoxEvents() an array of AutoCompleteBox controls is iterated through to locate the ToggleButton for each control and attach a Click event handler to it.  Doing this avoids hard-coding the event handler in the control template so that it can be defined just about anywhere you’d like without running into code scoping issues. 

Note: Keep in mind that if you plan on using the customized AutoCompleteBox control in several places it may be worth the time to create a custom control that derives from AutoCompleteBox to avoid having to put the ToggleButton event handler code and the HookAutoCompleteBoxEvents code into each page or user control. 

 

Logo

For more information about onsite, online and video training, mentoring and consulting solutions for .NET, SharePoint or Silverlight please visit www.thewahlingroup.com/.

7stacks Does OS X Stacks in Windows 7 Style [Downloads]

Windows only: Application launcher 7stacks adds the Stacks functionality of Mac’s OS X to Windows 7, including Aero transparency effects that blend into your taskbar perfectly.

To create your own stacks, launch the application, pick a folder and the type of launcher you want, create a shortcut on the desktop, and then right-click the shortcut and pin it to the taskbar. You can pin up to 10 shortcuts onto the taskbar this way, and you can choose between Menu, Grid, or Stacks (pictured). You don’t have all of the functionality that the latest version of StandaloneStack gives you, but it blends into the desktop really well with the Aero transparency effects, making it well worth a look for anybody using Windows 7.

7stacks is a free download for Windows 7 only. For more, check out how StandaloneStack is an awesome file-browsing widget, or our other favorite methods of consolidating taskbar launchers with Jumplist and switching folders with Folder Menu.

Update: Numerous readers point out that you’ve always been able to dock folders to the Windows taskbar by right-clicking on the taskbar and choosing New Toolbar from the Toolbars menu. This application simply does it with eye-candy effects instead of a plain menu.

7stacks [Alastria Software via Into Windows]





Firefox 3.5 Officially Available for Download [Downloads]

Windows/Mac/Linux: The final version of the Firefox is starting to show up on Mozilla’s web site, and some readers are reporting update notices. Here are a few links and how-tos you should check out before downloading that browser.

  • Add-on Compatibility Center – See whether the popular extensions that make up 95% of add-on downloads are compatible with Firefox 3.5 before you download. It’s looking pretty green and good at the moment, with the notable exception of Tab Mix Plus.
  • Top 10 Firefox 3.5 Features – Breaking down the Private Browsing Mode, TraceMonkey JavaScript engine, little interface features, and bigger changes to the increasingly popular open-source web browser.
  • Disable location-aware browsing and tab tearing – If those features sound more like privacy invasion and mouse-clenching hassle, respectively, they’re pretty easy to turn off.
  • Make your extensions work with (Firefox 3.5) – Originally written for the big (bigger?) Firefox 3.0 upgrade, but this little about:config tweak should keep those extensions not yet upgraded working with 3.5 as well, assuming you don’t mind potential bugs.
  • Weave synchronization tool – Mozilla's experimental synchronization project only works with Firefox 3.5—but, wait, that's out now! It's worth checking out, especially if you're running Firefox across multiple systems.
  • Firefox 3.5 Overview – It’s both a video run-through of Firefox 3.5′s features, and a test of the new no-Flash-needed video powers of Firefox 3.5 (non-HTML5-compliant browsers will just get an .ogv video download link).

Tell us about your Firefox 3.5 upgrade experience, or why you’re holding off, in the comments.





TubeMaster++ Update Makes Grabbing Videos and Music Easier [Downloads]

Windows only: Last year we shared TubeMaster Plus with you, an extremely handy program for downloading videos and music from streaming sites. TubeMaster++ has been released and comes with a slew of new features.

TubeMaster++ makes grabbing streaming videos and music incredibly simple. As long as TubeMaster++ is running, it will grab nearly every kind of media you watch over your internet connection thanks to its ability to scan the incoming data and not rely on the browser itself. Whether you’re watching a video in Internet Explorer, Firefox, or Opera, as soon as you start watching it, TubeMaster++ will begin capturing it.

You can save files, play them back right in TubeMaster++ and convert them. What formats can you convert into? A better question would be what formats can’t you convert into. You can convert audio formats into WAV, MP3, OGG, and AC3, among others. Video can be converted into dozens of formats and presets for mobile devices including the Creative Zen, iPod, Blackberry, PSP and PS3, various mobile phone sizes, and more universal formats like AVI and MPEG4.

TubeMaster++ does lose one feature from its predecessor: because of dependencies it has on installed software it is no longer portable. The trade off will be more than worth it for most people however as the new version is more stable, offers more features, has a built-in video and music search engine, and has dropped the upgrade requirement to download from adult video-sharing sites. TubeMaster++ is freeware, Windows only, and requires Java Runtime Environment and WinPcap (both of which are included in the installation if you don’t have them.)





Create an Oasis with Greywater

Greywater is the term for all household wastewater except for the toilet and kitchen sink. This is the only comprehensive book I know of on the subject, and in this fifth and expanded edition, Art Ludwig explains how to choose, build, and use a variety of simple greywater systems. There are clear drawings for sending washing machine water into the garden (with or without a drum), for putting diversion valves on bathtubs or showers, for creating “mulch basins,” for ultra-simple setups like “Garden Hose Through the Bathroom,” and “Dishpan Dump (Bucketing)” — the latter of which I've been practicing lately to the great benefit of both septic system and compost piles.

oasis-greywater2.jpg

There’s a large section on branched drains — splitting the flow and dispersing greywater to a number of mulch basins in the garden — using gravity flow, no pumps or electricity. Mistakes made in greywater systems over the years are documented here, along with suggested improvements, and there's a two-page System Selection Chart with a comparison of 18 different systems.

— Lloyd Kahn

[Complete plans for one of the book’s most broadly appealing projects -- a Laundry to Landscape Grey Water System -- are available, free, on the Oasis Design site. -- ES]

The New Create an Oasis with Greywater
Art Ludwig
2009, 144 pages
$21

Published by and available from Oasis Design

Or $15 from Amazon

Sample Excerpts:

oasis-greywater3sm.jpg
Simple Laundry Drum with Rainwater Harvesting

*

oasis-greywater4sm.jpg
Figure 7.6: Laundry Drumless Laundry

*
oasis-greywater5s.jpg

Related Entries:
The Tiny Book of Tiny Houses

Ratcheting Tube and Pipe Cutter

Pelican 0450

Wireshark 1.2 Includes 64-Bit Support, Mapping Integration [Networking]

Windows/Mac/Linux: Popular network analyzer Wireshark threw a lot of useful features into its 1.2 update, giving net traffic watchers OpenStreetMap+GeoIP integration, new capture file support, and other updates.

The previously featured utility is just as net-geeky as ever, showing packet movements as they happen along DNS, TCP, UDP, and other protocols and interfaces. On top of that, the app formerly known as Ethereal added a bunch of conveniences and tweaks:

  • Display filters now autocomplete.
  • A 64-bit Windows (x64) installer is now provided.
  • GeoIP database lookups.
  • Improved Postscript print output.
  • Support for Pcap-ng, the next-generation capture file format.
  • Column widths are now saved.
  • Capinfos now shows the average packet rate.

Hit up the link below for the full release notes, as well as details on known bugs. Wireshark is a free download for Windows, Mac, and Linux systems.





Get Firefox’s Ctrl+K Shortcut in Internet Explorer [Autohotkey]

Most modern browsers implement the Ctrl+K shortcut key for quickly focusing the built-in browser search box—and now you can use the same shortcut in Internet Explorer as well.

After reading about how to implement the Ctrl+L shortcut key in IE, reader Mike took it on himself to improve that script and add a number of other shortcut keys, including Ctrl+K to focus the search box, and Ctrl+Shift+Enter to automatically append “.org” to the end of anything typed into the address bar.

To use his script for yourself, create a new AutoHotkey script or add the following to your existing script:

#IfWinActive - Windows Internet Explorer ahk_class IEFrame
^k::Send ^e
^l::Send !d
^+Enter::
AutoTrim Off ; Retain any leading and trailing whitespace on the clipboard.
ClipboardOld = %ClipboardAll%
Clipboard = ; Must start off blank for detection to work.
Send {Ctrl Down}ac{Ctrl up}
ClipWait 1
if ErrorLevel ; ClipWait timed out.
   return
ClipboardNew = %Clipboard%
StringReplace, ClipboardNew, ClipboardNew, .com, .org
IfNotInString, ClipboardNew, .org
   ClipboardNew := ClipboardNew . ".org"
Send %ClipboardNew%{Enter}
Clipboard = %ClipboardOld%
return

This script listens for the Firefox-style shortcut keys, and then sends the Internet Explorer specific keys to the window instead, so you can switch between Firefox and IE without constantly hitting the wrong keys by mistake. Great job, Mike!

For more Windows shortcut goodness, check out how to make Win+E open the folder of your choice, learn how to use Caps Lock for hand-friendly navigation, and see how Taskbar Overlord tweaks the Windows 7 taskbar. Brand new to AutoHotKey and its time-saving ways? Peek at our beginner’s guide to learn how to add this script, or write your own.





Woodworking With SketchUp: Start at the End

Even if you’re experienced with using a computer, learning a new software program
presents two problems. The first is learning how to get around the program; the second
is learning how to make the program do what you want it to do. We’re excited about
what SketchUp can do to make woodworking easier and better, and I’ve been working
on developing methods to help folks learn it. I’ve come to realize that instead of
starting at the beginning by making simple models, you can dramatically shorten the
learning curve by starting at the end.

The real value of SketchUp is the amount of information within the model, and the
ease with which you can retrieve it. Even if you never draw a line with SketchUp,
you can better understand projects before you head to the shop. If you start with
an existing model, you can learn how to orbit, zoom and pan without the pressure of
creating something. You can learn how to move components of a project around, get
a better look, and take them apart without the fear of messing something up. The image
above is Roy Underhill’s Tool Chest from our June
2009
issue.  It's a good example because some of the joinery is tricky, and
that can be hard to describe with printed words and pictures. But it is easy to understand
if you take it apart and look at it from any angle or distance you want.

To get started, you need to download and install SketchUp on your computer. The software
is free from Google, and information about getting it can be found on the Popular
Woodworking SketchUp Page
. There, you can also find most of the models we have
made available (also absolutely free). You’ll find all of our models on our 3D Warehouse
collection, accessible through our SketchUp page. Browse the collection and download
something you’re interested in.


Spend some time just looking at the model from different points of view, using the
Orbit, Zoom and Pan tools. There's a lot of help available within the program, and
one of the best helpers is the Instructor window. You can find it under the Windows
menu in the program; when you have it open, it will show you the basic moves of each
of the available tools. Click on a tool and the Instructor window will tell you how
to use it.  When you're able to move around the model without getting lost or
bumping into things, start using the Move tool to take the model apart. In the image
above, I clicked on the top of the chest and moved it vertically. Notice that the
top moves as one piece and the entire top is highlighted in blue.


That lets you know that SketchUp thinks of the top as a single unit – a component.
If you click to highlight it, right click, then select Explode from the pop up menu,
you’ll be able to move the individual parts around. All of the parts of the model
can be found in the Components window. A good SketchUp model is organized this way.
When you draw things in SketchUp you draw lines and connected lines will form faces.
When you have enough lines and faces for something to look like a piece of wood, make
it into a component and it will behave like a piece of wood. Here we have a good look
at how the joints of the frame work with each other and with the panel.



Down at the base of the tool chest we can see what St. Roy was talking about in the
article. Again, all I did was orbit and zoom to the area I wanted to look at. Then,
using the Move tool, I disassembled the base. Putting it back together will give me
a good idea of the sequence of moves to make in the shop when working on the real
thing.

When I was a kid, I learned a lot about how things work by taking them apart. And
unlike the telephone in the kitchen that always sounded tinny after I put it back
together, you can take things apart in SketchUp fearlessly. If you mess things up
you won’t have to run away from home; you can download a fresh version of the model.
And in the process, you’ll learn a lot about the program before you start to draw.

– Robert W. Lang

p.s. I’ll be teaching several SketchUp classes, and we’ll have a “drop-in” clinic
available for additional hands-on training, at the Woodworking
in America: Furniture Construction and Design conference
, August 14-16 in St.
Charles, Ill. There’s still time to register.

Looking for More Free Woodworking Information?

• Sign up for our newsletters to get free plans, techniques and reviews HERE.
• Like tools? We do! Read our latest tool coverage HERE.
• Looking for free project plans? We have hundreds. Click HERE.
• Learn a new woodworking technique today. Click HERE.
• Want more videos? See all our free videos HERE.
• Check out our selection of half-price woodworking books HERE.
• Get 8 years of Popular Woodworking on one CD. Click HERE.

How To Play Sounds and Music in WPF

Introduction 

This is a re-post of an item that I had on my old blog.   As it seems to continue to get a lot of hits (when the site is up) I thought I would transfer it over here to the new site.

  It is more of a "here's how" approach than a "why it works that way" one.  Also I will be creating everything in code, not markup.  There are several more approaches and advanced techniques available via XAML that I won't be covering here.

PART 1  :  The SoundPlayer

1. Hard Coded File Path

  Starting with possibly the least realistic scenario, you can use the SoundPlayer to play a .wav file by pointing directly to a file via a hard coded path. 

 Code Copy

Imports System.Media

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim player As New SoundPlayer("C:Temp4WAY.WAV")
        player.Play()
    End Sub

 

     Note the Imports statement at the top. 

    This wave file will play asynchronously (I do wish someone would come up with an easier to type word than that!  -  it's nearly as bad as 'concatenation' )   But I digress….

    If it's a particularly large wav file, you can help things out by inserting a Load statement after the initialization and before the Play fires.  This will tee the player up to play without any kind of pause while it cranks up the file.   This is something well worth bearing in mind as we users have become more and more impatient of delays.

2.  Use a Content File

   One particularly useful approach which gets around all the potential problems of hard coding file paths is to add the file to your Solution Explorer items.  You can do this with the standard "Add Existing Item" selection from the IDE menu, adding the wav file directly to the list of files for the Project. 

  This now brings me to Frustration #1.  First, here's valid code to play the sound using a SoundPlayer object:

Code Copy
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button6.Click

        Dim player As New SoundPlayer
        player = New SoundPlayer("SND0103.WAV")
        player.Play()

    End Sub

   Now, before we move on, let's check the Solution Explorer:

     

    As you can see the file name is correctly entered and that file is sitting in the Solution Explorer's list of files that (you would think) it knows about.

   The key to fixing this problem is the 'Copy to Output Directory' Property.  By default, this is set to 'Do Not Copy'. 

 

 You need to change this to 'Copy Always' and you'll be back on track.

3. Audio File as Resource (Frustration #2)

   I wasn't going to include this option because it has generally caused me more trouble than it's worth (especially bearing in mind that there are several relatively trouble-free alternatives).  However, you can add a wav file as a Project Resource as normal and then play that Resource via a Stream.

   The syntax is:

Code Copy
  Private Sub btnResource_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnResource.Click
        Dim player As New SoundPlayer(My.Resources.canon)
        player.Play()

  End Sub

 

   Even with small, well tested files I often found that using this approach I would get a lot of unacceptable sound distortion (actually additional unrelated sounds to that expected).   I have tried it on several PCs,  each with different sound card configurations and the problems occur on them all.

5.  Other SoundPlayer Features

   In addition to the standard Play method, the SoundPlayer has a PlaySync method – in case you should rather unusually want the system to be locked until the sound has finished playing. 

  And finally if you want a sound to be repeatedly played, you can use the PlayLooping method to drive people mad; sanity can be restored by inserting the Stop method!

PART 2:  MediaPlayer and Media Element

    As you've already seen, the  SoundPlayer has some limitations.  It only understands wav format files and you can generally only play one wav file at a time (unless you start to get quite fancy with multithreading).  In many cases, the MediaPlayer or MediaElement will be a better option, but there is a good reason why I included the discussion of the SoundPlayer above.  In some situations on particular systems you will have  problems getting the  two Media components to work properly.  So it's always useful to know how to use the lighter weight SoundPlayer if you run into these problems in the future.

6.  But I Want to Play MP3 Files!

  -  or WMA or MID, etc. for that matter.  And this is a job for either the MediaPlayer or MediaElement.  Keeping to my approach of doing all the work in code, I'm therefore going to home in on the MediaPlayer.  (If you have a need to create a media object in XAML and have it play, pause, stop, trigger, etc, only in XAML then the MediaElement will be your tool of choice.)  

   Before abandoning the MediaElement approach altogether, I should point out that  you can create the MediaElement in XAML and then access it's properties and methods in code.   However, there is no advantage that I know of and in fact, the syntax is slightly more verbose and it also caused Frustration #4 – the fact that the audio file will only play once and then needs to be 'reset' by calling its Stop method; the Stop method apparently has the effect of returning the playhead to the beginning of the file.

  So let's look at the MediaPlayer in WPF.  It has an Open method which loads the file in the form of a URI.  This was Frustration #5 for me, as it took me a while to get past the problem of the "Value of Type 'String' cannot be converted to 'System.URI.'" error.  It took a lot more  than a quick search to finally discover that I needed simply to add the URIKind argument to the Open method; so the considerable amount of time I spent trying to do casts was wasted.   But maybe that's something I should have known. 

  It also has Play, Pause and Stop methods, plus the more sophisticated Balance and Volume properties.

  There is another small Gotcha involved in using this control.  Take a look at the following code snippet:

Code Copy

Dim mplayer As New MediaPlayer
mplayer.Open(New Uri("Godfather.mp3", UriKind.Relative))
mplayer.Play()

     It's hard to see anything wrong with that code snippet, but if you do try it you'll find that the audio will play for a short period of time and then – for no apparent reason – stop.   This is Frustration #6.

   As I understand it, what happens here is that the new MediaPlayer object is created, passed a URI for its source and then instructed to play.  Play begins but at that point seemingly the MediaPlayer closes itself, saying  "I've set the audio away, so my work here is done".  The end result is that at some unpredictable point in time the closed MediaPlayer is released from memory and will be disposed.  And of course as soon as it no longer exists there is no means for the sound to continue to be played.  So it stops in mid note!

   Anyway, having dragged you  laboriously through that explanation, you'll probably already have realised that the fix is simple.  All you need do is instantiate the MediaPlayer outside the scope of the click event so that the MediaPlayer will continue to exist throughout the lifetime of that Window or Page.  In other words, like this:

Code Copy
Class Window1
    Dim mplayer As MediaPlayer

  Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

        mplayer = New MediaPlayer
        mplayer.Open(New Uri("Godfather.mp3", UriKind.Relative))
        mplayer.Play()

    End Sub

End Class

   As with the SoundPlayer sample, the mp3 file has been added to the project files in Solution Explorer,  its Build property set to Content and its Copy To Output Director set to Copy Always.

  If the file is extra large and you get a pause before it actually begins to play then you can of course move the mediaplayer instantiation and Open code to, for instance, the Window Loaded event or some other place where the delay won't be so obvious.  It will then be teed up ready to go as soon as the Play method is invoked.

7.  Summary

   There isn't much else to add.  I think you now have the tools you need to  play sound and music files in WPF.  By the way, that does also mean both sounds and music at the same time, because you can have multiple instances of MediaPlayers running concurrently (or MediaPlayer(s) and a SoundPlayer running together).   Therefore  you can have almost any combination of sound files running, subject to the limitations of your system, that is.    

   I hope you will find this information useful in your future projects if you need to include sound and want to avoid the frustration of the learning curve.

  

   

WP Like Button Plugin by Free WordPress Templates