2,000 Things You Should Know About WPF

Everything a WPF Developer Needs to Know, in Bite-Sized Chunks

  • Home
  • About
  • Index
Posts Comments
  • Controls
  • Layout
  • Events
  • Basics
  • Blend
  • Graphics
  • XAML
  • Miscellaneous
  • Dependency Properties
  • Visual Studio

#165 – Overriding Metadata Can Result in Merged Metadata

December 24, 2010 Leave a comment

If you override metadata for a dependency property that a class inherits from its parent, you can specify one or more things to override:

  • The default value
  • The PropertyChangedCallback
  • The CoerceValueCallback
  • Other flags specified for UIPropertyMetadata or FrameworkPropertyMetadata

If you don’t specify all of these things, however, the items that you do not specify will be inherited from the parent.

For example, we created a child class of Slider and overrode metadata to provide a new default value for the Maximum property.  But the coercion behavior of Maximum in our new class behaves as it does for Slider.Maximum.  (Maximum can’t be set below Minimum).

Because we didn’t specify a CoerceValueCallback, the existing coercion logic is used.

When you do specify new metadata:

  • New default value replaces the existing one
  • PropertyChangedCallback is merged with the existing one  (both are invoked)
  • CoerceValueCallback replaces the existing one

Filed under Dependency Properties Tagged with CoerceValueCallback, Dependency Properties, OverrideMetadata, PropertyChangedCallback, WPF

Sean Sexton

Recent Posts

  • #1,219 – Expanding All Nodes in a TreeView by Default
  • #1,218 – Stretching Items in TreeView across Entire Control
  • #1,217 – Using Multiple HierarchicalDataTemplates in a TreeView
  • #1,216 – Creating a Custom ItemTemplate in a TreeView
  • #1,215 – Binding a TreeView to a Hierarchical Data Source

Blogroll

  • 2,000 Things You Should Know About C#
  • Britannica Geek
  • Sean on Twitter
  • Sean's Stuff

Calendar

December 2010
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Nov   Jan »

Top Posts

  • #547 - Specifying Colors by Name in Blend
  • #351 - Binding a CheckBox's IsChecked Property to a Boolean Variable
  • Index
  • #436 - Using a Drop Shadow with a Border
  • #210 - Specifying Colors in XAML As RGB Values
  • #1,107 - Accessing an Embedded Resource Using a Uri
  • #1,216 - Creating a Custom ItemTemplate in a TreeView
  • #1,217 - Using Multiple HierarchicalDataTemplates in a TreeView
  • #430 - Setting Width and Height Using Different Units
  • #588 - If You Handle PreviewKeyDown Event, KeyDown Won't Fire

Tags

Application Background Basics Binding Blend Border Brush Button Calendar Canvas CheckBox Color Colors ComboBox Commands ContentControl Controls Cursor Data Binding Dependency Properties Dependency property DockPanel Drag-and-Drop Events Expander FlowDocument Focus Fonts FrameworkElement Gradient Graphics Grid GridSplitter GroupBox HorizontalAlignment Image InkCanvas Input ItemsControl Keyboard Keyboard Focus KeyDown KeyUp Layout LinearGradientBrush ListBox Localization Manipulation Margin Measure Miscellaneous Mouse Panel Popup Radial Gradient Resources Routed Events ScrollViewer Shape Slider StackPanel TabControl Text TextBlock TextBox Tooltip Touch Input Transforms UIElement Visual Studio Window Windows WPF WrapPanel XAML

Blog Stats

  • 4,641,899 hits

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy