Questions tagged [dependencyobject]

The DependencyObject class enables Windows Presentation Foundation (WPF) property system services on its many derived classes.

The property system's primary function is to compute the values of properties, and to provide system notification about values that have changed. Another key class that participates in the property system is DependencyProperty. DependencyProperty enables the registration of dependency properties into the property system, and provides identification and information about each dependency property, whereas DependencyObject as a base class enables objects to use the dependency properties.

DependencyObject services and characteristics include the following:

  • Dependency property hosting support. You register a dependency property by calling the Register method, and storing the method's return value as a public static field in your class.

  • Attached property hosting support. You register an attached property by calling the RegisterAttached method, and storing the method's return value as a public static read-only field in your class. (There are also additional member requirements; note that this represents a WPF specific implementation for attached properties. For details, see Attached Properties Overview.) Your attached property can then be set on any class that derives from DependencyObject.

  • Get, set, and clear utility methods for values of any dependency properties that exist on the DependencyObject.

  • Metadata, coerce value support, property changed notification, and override callbacks for dependency properties or attached properties. Also, the DependencyObject class facilitates the per-owner property metadata for a dependency property.

  • A common base class for classes derived from ContentElement, Freezable, or Visual. (UIElement, another base element class, has a class hierarchy that includes Visual.)

100 questions
15
votes
2 answers

Improved IValueConverter -- MarkupExtension or DependencyObject?

I saw online 2 different approaches to enhancing an IValueConverter. One of them extended a ValueConverter from MarkupExtension, the other from DependencyObject. I can't extend from both, so I'm wondering if any one is better than the other?
michael
  • 14,844
  • 28
  • 89
  • 177
14
votes
1 answer

DependencyProperty from string

How do I convert a property name (in string) to a DependencyProperty? I have a set of property names, its values in string and a DependencyObject. Now I want to set these property values to the DependencyObject. Any idea on how this can be…
sudarsanyes
  • 3,156
  • 8
  • 42
  • 52
13
votes
1 answer

How is WPF's DependencyObject implemented?

Are there any articles that describe how the DependencyObject class in WPF works "under the hood"? Specifically, I'm curious about how dependency properties are stored and accessed efficiently.
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
11
votes
1 answer

What is a parent freezable? What does this error mean?

I'm getting this error: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable What does that even mean? Is it in English? Is the parent frozen, or is it just freezable? Any way to make a parent not…
mmr
  • 14,781
  • 29
  • 95
  • 145
9
votes
4 answers

WPF custom DependencyProperty notify changes

I have a class called MyComponent and it has a DependencyProperty caled BackgroundProperty. public class MyComponent { public MyBackground Background { get { return (MyBackground)GetValue(BackgroundProperty); } set {…
morsanu
  • 975
  • 20
  • 35
8
votes
2 answers

Customizing The DependencyObject Inheritance Tree

I'm struggling to find sufficient information about the property Inheritance Tree (or Inheritence Context) used by DependencyObject and DependencyProperty. I would like to use the value inheritence capability of DependencyProperty outside of a…
Mark
  • 9,320
  • 6
  • 57
  • 70
8
votes
1 answer

Why can I access DependencyProperties that are not registered on my DependencyObject?

I'm hoping someone can explain some unexpected behaviour I have come across whilst continuing my exploration of DependencyObjects and DependencyProperties. Given the following simple class: class SomeClass : DependencyObject { } I can…
Matt__E_
  • 277
  • 2
  • 9
7
votes
3 answers

Databinding on a IValueConverter

Does anybody know if it is possible to do databinding on an IValueConverter based class? I have the following converter: [ValueConversion(typeof(int), typeof(Article))] public class LookupArticleConverter : FrameworkElement, IValueConverter { …
Inferis
  • 4,582
  • 5
  • 37
  • 47
7
votes
1 answer

What use is a DependencyProperty whose ownerType is not a DependencyObject?

I've just started playing with DependencyProperties in WPF and I was wanting to check a couple of thoughts while I get to grips with them. Given the following (and ignoring naming convention for now): class MyTestClass { public static readonly…
Matt__E_
  • 277
  • 2
  • 9
6
votes
3 answers

Is it possible to get x:Name of a DependencyObject (Silverlight)?

I have a DependencyObject (an Interactivity Behavior), and I'd like to get its x:Name (just get, not set) from code. Is it possible? EDIT: Following AnthonyWJones's answer: I've inserted the following code into my base…
TDaver
  • 7,164
  • 5
  • 47
  • 94
6
votes
1 answer

Given a styled WPF DependencyObject, how can I get the Style Key in code?

I have a set of controls bound to data, on which I would like to programmaticaly add validators to the bindings. Currently I'm able to iterate over the visual tree to find those controls with bindings, and also add my validators to these controls.…
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
4
votes
1 answer

How to avoid the '[Unknown]' property does not point to a DependencyObject in path '(0).(1)[1].(2)' exception in wpf

On button click, Updating the ListBox ItemsSource collection. For 4 or 5 clicks its working fine but afterwards it throws an exception as '[Unknown]' property does not point to a DependencyObject in path '(0).(1)[1].(2)' I googled it & find the…
rohanw
  • 71
  • 1
  • 4
4
votes
1 answer

Make dependency object properties bindable as a static resource?

How to make an array of dependency object properties bindable for later binding as a static resource? The code I have now, it seems that my DependencyObject bypasses the dependency property system... I have the following class: public class…
John K
  • 109
  • 8
4
votes
1 answer

WPF DependencyProperty chain notification

im exploring WPF world, i find a great example on the web about how to use binding on xml http://www.codeproject.com/Articles/37854/How-to-Perform-WPF-Data-Binding-Using-LINQ-to-XML Now im trying to extends this example: i want to create a "class in…
4
votes
2 answers

Enabling direct content creation in XAML on a dependancy object

I have a class CollectionOfThings. As its name suggests its a simple collection of instances of the Thing class. Thing class has a public default constructor and two simple public get, set properties ID and DisplayName, both are string. …
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
1
2 3 4 5 6 7