Showing different text (or elements) in a disabled ToolTip versus an enabled ToolTip in WPF

I originally started this post with a title of “WPF ToolTip Child Element Visibility Based on the Parent of the ToolTip IsEnabled Property… and you are not it with a dirty dirty dish rag on your toe reading behind a dirty magazine”, but I decided that in the best interest of my sanity (read: “what sanity”) that I would make it a little more descriptive to what my goal for creating this functionality was and a lot less wordy (read: less words than the number of pieces of bubble gum in a dish that you wished for). Don’t ask.

After writing my last post about the advanced tooltip functionality in .NET 2.0 using the VisualTips component, I realized that WPF (Windows Presentation Foundation) lacked a way OOTB to create two distinctive tooltips on an element that could be displayed based on whether or not the control was disabled or enabled. VisualTips provides this functionality. This helps users to better understand what step they need to take before a control will become enabled and why the heck they can’t click on it. For instance, in MuvAudio, the “Record” button is disabled until an item has been added to the playlist. When they move their mouse over the button, as of right now, they get no message whatsoever. They don’t even get the regular tooltip telling them what it would do if it were enabled. (I’m in the process of implementing the VisualTips so the next version of MuvAudio will have the functionality I’m about to explain). It would make sense to do the following:

  • Make the Record button, in the disabled state, display a message that says: “To being recording you must first add at least one audio file to the playlist. You can do this by double-clicking anywhere in the playlist area or by clicking on “Playlist”, “Add File(s)” and selecting the audio files that you would like to record.”
  • Make the Record button in the enabled state display: “Starts the recording process.”

To do this in WPF I had look at the problem from a different perspective. Now, I’m not the greatest programmer in the world and I am definitely am open to suggestion, so please leave me comments, but this is what I came up with:

To add a ToolTip that displays different text based on the enabled/disabled of a button (this can be replaced with any element) that it is the child of:



The important parts are as follows:

Visibility=”{Binding Path=IsEnabled, Converter={StaticResource ToolTipElementVisibilityConverter}, ConverterParameter=VisibleOnDisabled}”

Visibility=”{Binding Path=IsEnabled, Converter={StaticResource ToolTipElementVisibilityConverter}, ConverterParameter=VisibleOnEnabled}”
  • In the declaration of the Element that will contain the tooltip, you need to make sure you have ToolTipService.ShowOnDisabled=”True”
    because this allows the tooltip to still be displayed when the element is disabled.
  • You need to set the DataContext of the tooltip as follows: DataContext=”{Binding Path=PlacementTarget, RelativeSource={RelativeSource Self}}”; this allows us to set the binding of the IsEnabled property in the elements of the tooltip.
  • Finally, you need to set the Visibility using a binding with a Converter and a ConverterParameter based on when you want the items to be displayed. In the above example we only want one of the textblocks to be displayed in either state so we have the parameter set to the opposite of each other:
    • The Path is bound to the IsEnabled property of the element that is the parent of this tooltip (as described above).
    • The Converter is a converter that we created that returns back the Visibility we want (Visible or Collapsed) based on the IsEnabled property and the ConvertParameter.
    • The ConverterParameter is a string that we use to tell the item to be visible when the item is enabled or when the item is disabled. The two choices are VisibleOnDisabled and VisibleOnEnabled.

The actual converter is contained in the sample project.

As a side, I looked into using enums for the parameter instead of strings but they just added extra code that doesn’t get taken advantage of (Visual Studio 2008 Beta 2 doesn’t display auto completion for enums in xaml). An example would look like this: “ConverterParameter={x:Static local:ToolTipElementVisibility.VisibleOnDisabled}”, where “local” is a xml namespace you would add to the window declaration.

The other pieces of the puzzle are as follows:

  1. Add an xml namespace declaration for the converter class to reference the converter (I prefer to add this to the window.xaml the tooltip will be used on): xmlns:cvrt=”clr-namespace:MuvEnum.ToolTipElementVisibility.Converters”
  2. Add the converter as a resource in the same window.xaml you used in #1: <Window.Resources>        <cvrt:ToolTipElementVisibilityConverter x:Key=”ToolTipElementVisibilityConverter” />    </Window.Resources>

A full sample is attached and has a compiled executable.

You’re free to use this code in any project you like. A reference to this post would be appreciated but is not required.

After I finished this code, which I’ll definitely be using in a soon to be finished WPF product, I realized that this goes above and beyond what the VisualTips for .NET can do by allowing a user to create distinctively different tooltips based on the enabled and/or disabled state of the element they are a child of thanks to the ability of tooltips to host any WPF element.

I assume this idea can be used to bind to other Boolean properties of elements and not just the IsEnabled. One of the most exciting things about WPF is the ability to create things that even those that created WPF didn’t even foresee. Now that deserves a post of its own.

WPF ToolTip Element Visibility Sample Project

Upgrade your .NET Tooltips to the Office 2007 style

I’m a big fan of the Office 2007 style tooltips and one of the areas where I feel .NET lets me down a little is in the ToolTip department.

Here’s the default .NET ToolTip:

Now take a look at the following ToolTips:

Not only do they look much better, but they also provide some very needed features.

  1. Each ToolTip can be defined with an access key, F2 in the above samples, which provides you with the ability to give extra functionality for each ToolTip.
  2. Each ToolTip can be given a specific “disabled” message that you can define to let your users know why a button is disabled and what the next step would be to get it enabled. In the regular ToolTips, if a control is disabled then no ToolTip is shown.

The best part about the above ToolTips is that you can add this functionality to your program for free thanks to SKYBOUND. Their free .NET component is called VisualTips and it’s a breeze to implement. They also have a bunch of other free components to help you spruce up your application so definitely check them out.

On a side note, WPF (.NET 3.0) provides similar functionality out of the box and here is a xaml sample (not the coolest, but can be beefed up easily):

<Button x:Name=”btn1″ HorizontalAlignment=”Left” VerticalAlignment=”Top” Content=”Button” IsEnabled=”False” ToolTipService.ShowOnDisabled=”True” >


<ToolTip x:Name=”buttonToolTip”>


<Image Source=”” />

<TextBlock x:Name=”buttonToolTipText” Text=”This is a sample tooltip in WPF”/>





The ToolTipService.ShowOnDisabled=”True”
attribute makes it so the ToolTip is displayed whether or not the control it is attached to is enabled or disabled. In the below screenshot, the control is disabled and you can see the sample WPF ToolTip.

ToolTips are an important part of the usability of any application, especially when it helps remove the need of requiring the user to read the manual before beginning use of your application.

Replacing Notepad.exe in Windows Vista

I know this has been covered on other sites but I thought I would post it here for the benefit of our readers.  Why would you want to do this?  Well, because Notepad that comes with Windows is, well, if you’ve used it then you know what it’s like and have probably moved on to something better. However, simply adding an additional text editor doesn’t change the fact that Notepad will still open as the default editor for many files within Windows Vista.  So how do you accomplish this?  It’s (almost) simple:

  • Open a command-prompt with administrator priveleges (right-click, run as administrator).  If you have UAC disabled then you can open a regular command-prompt.
  • Take ownership of notepad.exe using takeown /f c:\windows\system32\notepad.exe
  • Grant yourself full access rights using cacls c:\windows\system32\notepad.exe /G <username>:F (replacing <username> with your username)
  • Using Explorer, replace notepad.exe with the editor you would like to use after renaming it to notepad.exe
    • If you are using Notepad2 to replace Notepad you would just rename Notepad2.exe to Notepad.exe

Command Prompt – Easily Paste Paths and Filenames

Here’s a quick tip I found out about the other day from a fellow co-worker:

You can drag and drop a single file or folder onto the command prompt and it will paste the path automatically. This saves time compared to the old-fashioned way of selecting the address bar, copying, then right-clicking on the command prompt and pasting (I always hit ctrl-v which gives you the wonderful “^V”, which you then have to delete and do the fantastically fun right-click and paste feature).

Works on 2000/XP/2003.

For Vista, this functionality has been removed for the following reason:

This was done to reduce the command window’s dealings with the dragged data object.

This means on Vista, you must shift-right-click the file or folder and choose “Copy as Path” and then right-click on the command window and paste, which brings into play the dreaded “Ctrl+V” issue I mentioned above.

Oh well, what can you do?

(please don’t say “don’t run Vista”)

Enabling /NOGUIBOOT in VistaPE (WinPE 2.0)

Now first thing’s first…why would you want to do this?  Well if any of you have booted to VistaPE or Vista you will have noticed the tastefully bland boot screen that is mostly empty except for a wonderful leprechaun green status bar that doesn’t even really show a status at all (as if a bar going across the screen over and over again actually means anything).  This is where /NOGUIBOOT comes in.  By enabling NO GUI BOOT you are actually turning off this animated progress bar and turning on a static bitmap image instead.  This bitmap resides in winload.exe.mui and the default one is still pretty lacking in the excitement department.

MyVistaBoot winload.exe.mui Screenshot

There are plenty of websites out there that will help you create a new winload.exe.mui and they all talk about how easy it is to enable this in Vista, is my favorite and it has pre-made boot screens for you. All you have to do is use ‘msconfig’ to put a checkmark in “No GUI Boot”. But alas, it is not such a simple task when you’re dealing with VistaPE which does not contain msconfig. For those of you not familiar with what BCD is, it is the Boot Configuration Data file that has replaced the boot.ini from Windows XP and it cannot be modified as a text file, you must use BCDEDIT.exe to make changes to it (or EasyBCD from NeoSmart Technologies). Here’s the easy solution using BCDEDIT:

  1. Find where your VistaPE BCD is, ie. if on your usb key at e: then it’s e:\boot\bcd

  2. Use the following command: bcdedit /set {default} quietboot on /store e:\boot\bcd

It’s that simple! The hard part is tracking down the intelligent person at Microsoft that named the command switch “quietboot” when what it sets is the /NOGUIBOOT switch in the BCD string.  Maybe someone will knock some sense into him/her.  Let me know and I’ll send you $5.00

Taken from Microsoft MSDN:

quietboot [ on | off ]

Controls the display of a high-resolution bitmap in place of the Windows boot screen display and animation. In operating systems prior to Windows Vista, the /noguiboot serves a similar function.