Monday, January 3, 2011

How to Create a Splash Screen for a WPF App

Creating a Splash Screen for a WPF application is extremely simple. Simply add your image into your project and set the build action to SplashScreen.

image

That’s pretty much all it takes. When you start up your application, you will see your splash screen image appear while the application is initializing.

You can also add a a new item to your project and select SplashScreen from the available templates

image

This will add a default image which you can then swap for your own, custom splash screen.

Yet another approach would just be to use the Splash Screen APIs. You can create a new SplashScreen object and call it’s Show method to display it and it’s Close method to, you guessed it, close it.

Happy Coding!

 

Wednesday, December 15, 2010

WPF VisualStateManager GotoState Bug

So, I just wasted a couple of hours trying to figure this one out so I thought I’d post about it so you guys don’t have to waste as much time as I did on it.

The WPF VisualStateManager implementation is still not as rock solid as Silverlight’s implementation (ok, let’s face it, Silverlight’s implementation is far from rock solid too, but it is much better of at this point). If you are trying to call the VisualStateManager.GotoState Method on a Window, you are going to be very very frustrated. Why? Because it doesn’t work. If you are inside a user control, it is fine, but inside of a Window… nope!

Instead of calling this

VisualStateManager.GoToState(this, "stateName", true);


You are going to need to call this



VisualStateManager.GoToElementState(this.RootElement as FrameworkElement, "stateName", true);


That should do it for you. Microsoft is aware of the issue and has promised to fix this, but who knows when that’s going to happen.



Happy state-changing!



 




WPF - Accessing Resource Dictionaries in Separate Assemblies

There are certain situations where you will need to access resource dictionaries outside of your application. For example, you may want to share one resource dictionary among several applications that share the same styles.

What you want to do is use WPF’s pack URI Scheme.

Remember to include a reference of the assembly containing the resource dictionary (YourAssembly) in the application project. Then, all you have to do is use this rather strange looking syntax to access that resource dictionary within your xaml.

<ResourceDictionary Source="pack://application:,,,/YourAssembly;component/Subfolder/YourResourceDictionary.xaml"/> 

There are many variations of this syntax that you can use. Which one is right for you depends on exactly what you are trying to do. The above syntax should work for a majority of the situations. Accessing these resources can be done in both xaml and the code behind.

For more information on the pack URI Scheme syntax, follow this link:

http://msdn.microsoft.com/en-us/library/aa970069(v=vs.85).aspx

Note - this syntax is not only for resource dictionaries. This is useful for accessing several types of data files like images for example. This is commonly used for accessing resource dictionaries, but it is not limited to that.

 

Friday, August 13, 2010

Silverlight: Blank Line in TextBlock

 

This will be a relatively short one. I just wanted to post this out there in case anyone is wondering how to do this.There are several ways to create a blank line within a single textblock (or label) in Silverlight. The simplest is to use these special characters:

&#xd;&#xa;

So, the following xaml

<TextBlock Text="hello&#xd;&#xa;world"/>

produces this text block

image

Tuesday, July 13, 2010

Bing Videos… Are you Kidding Me?!?!?!?

So there is nothing technical about this post, but I found it interesting. I have been a big supporter of Microsoft Silverlight, but I do find it a bit frustrating when I find out they don’t use their own technologies internally. Check this post out, it points out how Microsoft uses Flash for their Bing videos rather than Silverlight!

image

Now, when you click on the video, you are taken to a Silverlight player where you can view the entire clip, but why the use of Flash for the preview? Why not Silverlight? What was the technical challenge that caused them to go with Flash?

http://geekygab.blogspot.com/2010/07/bing-videos-are-you-kidding-me.html

 

Friday, July 2, 2010

Get Local Time Zone

Here’s a quick post on how to get the local time zone in your Silverlight Applications. You need to use the System.TimeZoneInfo class to get this information. This simple call will give you your local time zone.

TimeZoneInfo.Local.StandardName



If you have a DateTime value you want to convert to local time, just call the ToLocalTime method on it and that should do it. You can also use the ToUniversalTime method on it to convert it to UTC time.



Thursday, June 17, 2010

Snippet Designer

I am a big proponent of code snippets. I use them all the time and I tend to write my own snippets for code I write over and over. Recently, I found a nice Visual Studio extension out in codeplex that lets you write your own code snippets a bit faster than editing the xml yourself. Although it isn’t very difficult, I have found this new method of writing snippets a bit faster, so I thought I would blog about it. If you are interested in trying this out, here is the url: http://snippetdesigner.codeplex.com/

The extension takes no time to install. once you have it installed, all you do is select the code you want to be created as a snippet and right click and export it as a snippet. From there, you open up a nice designer that lets you change the details of your snippet and create Replacements. It is a very cool tool and once you play around with it for a while, you’ll be creating snippets in no time and well on your way to saving time in your coding.

image

image

Enjoy!