WPF Tip: Overriding Metadata

October 19, 2010

Every dependency property is associated with some metadata, specifying (for instance) the property’s default value, various flags (affects render, inheritance down the visual tree and much more). Sometimes when creating custom elements, we need to change aspects of an inherited dependency property. For example, in my last post I showed a custom Shape called TickCircle, that uses lines to draw itself. These lines use the Stroke property (a Brush) inherited from Shape to draw those lines. The problem is that the default value of Stroke set by Shape is null, which means users of my TickCircle have to supply...
tags: , , ,
no comments

Creating a Custom WPF Shape

October 17, 2010

The WPF Shape class is the abstract base of various simple shapes, namely Line, Ellipse, Rectangle, Polyline, Polygon and Path. Path is not really simple, as it can show any given Geometry. There are multiple ways to create custom visual objects in WPF and selecting the best base class is not always easy. The Shape class derives from FrameworkElement, meaning it supports layout, transformations, styles, etc., so it’s a convenient starting point for new shapes. Shape exposes properties such as Fill, Stroke, StrokeThickness and Stretch. A custom Shape only needs to override the protected DefiningGeometry property, returning a...
tags: , , ,
one comment

Windows Platform Developers User Group meeting

October 6, 2010

This evening was a WPDUG meeting on CLR hosting and CLR profiling. Thank you all for coming! It was a pleasure to see so many of you there. My session was on CLR hosting, using the new CLR 4 hosting API. This is done using native code (C++) that uses COM for communication between the CLR and the host, both ways. I showed how to enumerate the installed runtimes, how to load a specific CLR (a new feature of CLR 4 – the ability to host multiple CLRs in a single process), how to create an application domain...

WPF Menu Customization

October 1, 2010

Menus are the most well known of all user interface elements. Although their popularity has declined in recent years, in lieu of toolbar and the famous office style ribbon, they are still useful. In WPF, a menu is constructed by a Menu class that mostly hosts MenuItem objects, that can nest to any needed level. Customizing the look of WPF menus (and context menus) can be surprisingly difficult. The first, simplest, and most obvious way of customizing a WPF menu is to tweak its properties, such as Background, Foreground and FontSize. This, however, leaves much to be desired. Here’s...
tags: , , , ,
6 comments