I like using CSS classes to format specific content of my blog posts, in order to keep my formatting centralized. I prefer HTML that looks like this over inline styles:
If you invoke the <span class="code">GetData</span> method, ...
Quickly inserting CSS directives is something you can’t easily do with Windows Live Writer. This started to annoy me while writing an article, so I came up with two simple plug-ins that do just that: Formatting selected text through CSS classes.
Read more…
I’ve first encountered this issue with my WPF NotifyIcon, and now again while writing a plug-in for Windows Live Writer: If you try to display a WPF popup without any Windows open (the Popup is the only UI component there is), certain controls such as TextBox, ListView, or ListBox don’t receive proper mouse and/or keyboard input, and cannot be selected.
The reason for this issue is buried in the WPF framework, and how it interacts with Windows. Fellow WPF Disciple Andrew Smith pointed me in the right direction:
…because a Popup’s HWND has the WS_EX_NOACTIVATE so the WPF framework will not attempt to actually focus the associated hwnd (because its usually used with a window and you don’t want to deactivate the window when you focus something in the popup).
Accordingly, you’ll have to fiddle with Windows Interop to make things work. Here’s the snippet:
public static class WinApi
{
/// <summary>
/// Gives focus to a given window.
/// </summary>
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public static void ActivatePopup(Popup popup)
{
//try to get a handle on the popup itself (via its child)
HwndSource source = (HwndSource)PresentationSource.FromVisual(popup.Child);
IntPtr handle = source.Handle;
//activate the popup
SetForegroundWindow(handle);
}
}
I released an update to my WPF NotifyIcon, which fixes two issues:
- Interactive Popups should now fully support all control types.
- The control can now be used in Windows Forms projects, if you need more functionality than the built-in component.
The solution now comes with an additional WinForms sample project, which shows how to display a WPF user control as an interactive popup.
Download link and further information can be found on the control’s home page:
http://www.hardcodet.net/wpf-notifyicon
I updated NetDrives, which fixes a registry issue when it comes to saving the application settings. Functionality is still the same, though.
Project Page: http://www.hardcodet.net/netdrives
I just made a few minor updates to two libraries which assemble as set of helper classes for C# and WPF and thought: Why not share them? The libraries aren’t really intended to be used directly in your code, but you might find one or another helper method or snippet that might make a nice addition to your own toolbox 🙂
Hardcodet.Commons (C#, .NET 3.5)
Common helper classes and snippets (simple base classes, file management, weak events, extension methods etc.)
Hardcodet.Wpf.Commons (C#, .NET 3.5)
Stuff I commonly use in WPF projects, such as checking for design time, base classes for commands and converters, data binding helpers and other stuff.
I’ll keep these libraries up-to-date, version history will be posted here.
History:
2009.09.14 Initial blog release