Questions tagged [dependency-properties]

A property in WPF and Silverlight that can be set through methods such as, styling, data binding, animation, and inheritance.

Dependency property is a property backed by a static DependencyProperty instance.

The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs and to provide notification when computed value changes. The priority of inputs which contribute to computation is listed in Dependency Property value precedence overview.

Dependency properties usually have CLR "wrappers": the actual get and set implementations for the property.

Dependency property declaration (static field + wrapper) is a boilerplate code, which follows a certain pattern and can be generated by IDE (check Visual Studio shortcuts here).

General information: Dependency Property Overview

2294 questions
13
votes
5 answers

Difference between Attached and non-Attached Dependency Properties in Silverlight

Okay Stackers, I've spent a good couple of hours on this question, and I want to know if anybody has a definitive answer. For all the research I've done, I can't find ANY difference between .Register and .RegisterAttached in Silverlight. Now,…
13
votes
3 answers

How to propagate PropertyChanged changes in DependencyProperty

I have a class which implements INotifyPropertyChanged. An instance of this class is declared as a DependencyProperty in a Window, e.g., public IMyClass MyClass { get { return (IMyClass)GetValue(MyClassProperty); } set {…
tofutim
  • 22,664
  • 20
  • 87
  • 148
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
13
votes
4 answers

How to correctly bind to a dependency property of a usercontrol in a MVVM framework

I have been unable to find a clean, simple, example of how to correctly implement a usercontrol with WPF that has a DependencyProperty within the MVVM framework. My code below fails whenever I assign the usercontrol a DataContext. I am trying…
Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
13
votes
2 answers

How can I fix the DependencyPropertyDescriptor AddValueChanged Memory Leak on AttachedBehavior?

I know I need to call RemoveValueChanged, but I have not been able to find a reliable place to call this. I'm learning that there probably isn't one. I looks like I need to find a different way to monitor the change then adding a handler using…
scuba88
  • 458
  • 2
  • 4
  • 13
13
votes
2 answers

Binding on DependencyProperty of custom User Control not updating on change

I'm having difficulties with databinding on my custom user control (s). I created an example project to highlight my problem. I'm completely new to WPF and essentially MVVM as well, so bear with me... I created a simple view that uses databinding…
user2367999
  • 133
  • 1
  • 1
  • 5
13
votes
1 answer

How can I add logic to an existing dependency-property callback?

I'm trying to add a PropertyChangedCallback to UIElement.RenderTransformOriginProperty. An exception is thrown when I try to override the PropertyMetadata. I have searched MSDN and Google, and all I have been able to come up with is this.…
Giffyguy
  • 20,378
  • 34
  • 97
  • 168
12
votes
3 answers

Dependency Property With Default Value Throwing StackOverflowException

I'm using the WPF SQL Connection User Control. I am having an issue with it throwing a StackOverflowException whenever I have it on a tab (AvalonDock DocumentTab) which has been opened, closed, and then opened a second time. I've messed around with…
Mike G
  • 1,956
  • 1
  • 30
  • 62
12
votes
5 answers

Silverlight: How to receive notification of a change in an inherited DependencyProperty

I have a control which inherits from (you guessed it) Control. I want to receive a notification whenever the FontSize or Style properties are changed. In WPF, I would do that by calling DependencyProperty.OverrideMetadata(). Of course, useful…
MojoFilter
  • 12,256
  • 14
  • 53
  • 61
12
votes
3 answers

Must create DependencySource on same Thread as DependencyObject

I have an application written in wpf, which downloads some webpages, parses html code and saves some values. class ListOfItems { public List ListToBind; public void DownloadItems() { Task.Factory.StartNew(() => …
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
12
votes
3 answers

Why Dependency property are declared as static readonly?

It is clear to me why dependency property are static and the question still remain on my mind is why we need to use Readonly keyword at the time of declaration of Dependency Property.
pchajer
  • 1,584
  • 2
  • 13
  • 25
12
votes
1 answer

Why "propdp" code snippet doesn't use the nameof operator for the name of the registered property?

If you insert the snippet propdp, it doesn't use the nameof operator for the property name in the first parameter of the DepencendyProperty.Register method and it creates something like this: public string Text { get { return…
12
votes
2 answers

UserControl Animate Button's Background

I'd like to animate a Button's Background if the Mouse is over the Button. The Button's Background is bound to a custom dependency property I've created in the Code Behind of my UserControl ... Background="{Binding BGColor,…
Th1sD0t
  • 1,089
  • 3
  • 11
  • 37
12
votes
1 answer

What is the need for Coercing a Dependency Property?

I saw an example where there were 2 dependency properties: public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register("CurrentReading", typeof(double), typeof(Gauge), new…
Rohan Gurjar
  • 121
  • 1
  • 4
12
votes
2 answers

Dependency Property assigned with value binding does not work

I have a usercontrol with a dependency property. public sealed partial class PenMenu : UserControl, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) …