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
375
votes
14 answers

INotifyPropertyChanged vs. DependencyProperty in ViewModel

When implementing the ViewModel in a Model-View-ViewModel architecture WPF application there seem to be two major choices how to make it databindable. I have seen implementations that use DependencyProperty for properties the View is going to bind…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
142
votes
3 answers

What is a dependency property?

What is a dependency property in .Net (especially in WPF context). What is the difference from the regular property?
e11s
  • 4,123
  • 3
  • 29
  • 28
98
votes
5 answers

What's the difference between a dependency property and an attached property in WPF?

What's the difference between a (custom) dependency property and an attached property in WPF? What are the uses for each? How do the implementations typically differ?
kenwarner
  • 28,650
  • 28
  • 130
  • 173
85
votes
6 answers

Listen to changes of dependency property

Is there any way to listen to changes of a DependencyProperty? I want to be notified and perform some actions when the value changes but I cannot use binding. It is a DependencyProperty of another class.
Rasto
  • 17,204
  • 47
  • 154
  • 245
78
votes
2 answers

How do You Create a Read-Only Dependency Property?

How do you create a read-only dependancy property? What are the best-practices for doing so? Specifically, what's stumping me the most is the fact that there's no implementation of DependencyObject.GetValue() that takes a…
Giffyguy
  • 20,378
  • 34
  • 97
  • 168
70
votes
2 answers

Is there a way to specify a custom dependency property's default binding mode and update trigger?

I would like to make it so that, as default, when I bind to one of my dependency properties the binding mode is two-way and update-trigger is property changed. Is there a way to do this? Here is an example of one of my dependency properties: public…
Justin
  • 2,399
  • 4
  • 31
  • 50
62
votes
3 answers

What are the defaults for Binding.Mode=Default for WPF controls?

In WPF Binding.Mode, when selecting Default, it depends in the property being binded. I am looking for some list or some convention or any information for the defaults for the various controls. I mean, what properties are TwoWay by default and so…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
62
votes
7 answers

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

From a custom control based on TextBox, I created a property named Items, in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it…
mgottschild
  • 1,015
  • 1
  • 9
  • 10
59
votes
3 answers

What's the difference between Dependency Property SetValue() & SetCurrentValue()

The reason why I am asking this is because I was recommended by @Greg D (from this question) to use SetCurrentValue() instead, but a look at the docs and didn't see whats the difference. Or whats does "without changing its value source"…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
52
votes
9 answers

Error while removing project dependency in VS2010

I have a large solution with number of projects. Some the projects depend on others (never a circular dependency though). When I tried to remove a dependency of a project, I am getting an error message like "The dependency was added by the project…
Aneesh Narayanan
  • 3,220
  • 11
  • 31
  • 48
51
votes
9 answers

Hiding inherited members

I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes inherit dependency properties which have become vestigial and can be a…
MojoFilter
  • 12,256
  • 14
  • 53
  • 61
43
votes
4 answers

DependencyProperty.Register() or .RegisterAttached()

What's the difference between the two, when should RegisterAttached() be used instead of .Register()?
Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
43
votes
2 answers

Setters not run on Dependency Properties?

Just a short question, to clarify some doubts. Are setters not run when an element is bound to a dependency property? public string TextContent { get { return (string)GetValue(TextContentProperty); } set { SetValue(TextContentProperty,…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
42
votes
2 answers

Why dependency properties?

Why did Microsoft go the route of making dependency properties and dependency objects instead of using reflection and maybe attributes?
Mr Bell
  • 9,228
  • 18
  • 84
  • 134
38
votes
1 answer

How to use Attached property within a style?

I have created an Image within a ButtonStyle. Now I have created an Attached Property so that I can set the Source for that Image. Should be straight forward but I am stuck with it. This is my shortened ButtonStyle:
Houman
  • 64,245
  • 87
  • 278
  • 460
1
2 3
99 100