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
22
votes
1 answer

WPF ValidationRule with dependency property

Suppose you have a class inheriting from ValidationRule: public class MyValidationRule : ValidationRule { public string ValidationType { get; set; } public override ValidationResult Validate(object value, CultureInfo cultureInfo)…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
22
votes
2 answers

Why dependency properties in WPF has to be Static

Why a dependency property has to be Static? I have seen that it has been already asked in some post here, but I am not able to understand it properly. It will be great if someone can help me understand with a small snippet too.
Jasmine
  • 5,186
  • 16
  • 62
  • 114
22
votes
2 answers

Binding to UserControl DependencyProperty

I have created a UserControl with some DependencyProperties (in the example here only one string property). When I instantiate the Usercontrol, I can set the property of the UserControl and it is shown as expected. When I am trying to replace the…
Lightbringer
  • 765
  • 1
  • 4
  • 16
21
votes
6 answers

'{DependencyProperty.UnsetValue}' is not a valid value for property 'FocusVisualStyle'

I have a weird error I'm trying to debug with no luck. I have subclassed hwndhost showing some content, I have the following function in that class to set to fullscreen: private void SetFullScreen(bool enable) { if (enable) …
DaveO
  • 1,909
  • 4
  • 33
  • 63
21
votes
4 answers

WPF override IsEnabled from Parent

I just searched for a way to enable a child control while the parent control has IsEnabled = false. All answers that I have found up to now say that it is not possible - one has to enable the parent and disable the child controls except the ones…
LionAM
  • 1,271
  • 10
  • 28
20
votes
4 answers

What is a dependency property? What is its use?

Possiblity: What is a dependency property? What is a dependency property? How does it differ from a normal property? What is the purpose of dependency properties? And why it is used, when it is used?
Thiru G
  • 620
  • 2
  • 6
  • 17
20
votes
3 answers

Maven: Import pom properties from different pom

I would like to import properties from a project X pom file into my project Y pom such as library versions. I do not want to make the project X my project's parent. I have tried to include project Xs pom in the dependency management section as an…
user518066
  • 1,277
  • 3
  • 23
  • 35
20
votes
4 answers

What's the framework mechanism behind dependency properties?

I have been reading about dependency properties in several books but all have one thing in common, they just tell us how they are implemented( using static readonly DependencyProperty etc.) but does not tell the exact way they work from inside. I…
Akshay J
  • 5,362
  • 13
  • 68
  • 105
20
votes
2 answers

WPF usercontrol Twoway binding Dependency Property

I created a Dependency Property in the usercontrol, but however changes in the usercontrol was NOT notified to the Viewmodel Usercontrol
Spen D
  • 4,225
  • 9
  • 39
  • 47
19
votes
2 answers

How to bind to a WPF dependency property when the datacontext of the page is used for other bindings?

How to bind to a WPF dependency property when the datacontext of the page is used for other bindings? (Simple question)
Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139
19
votes
5 answers

How to debug DependencyProperty.Unsetvalue errors when the InnerException is null

I have a custom login usercontrol that has a normal textbox and a passwordbox. Blend refuses to cooperate with the PasswordBox saying that "DP.UnsetValue" is not valid for PasswordChar property. However the project compiles and runs fine in Blend…
TWood
  • 2,563
  • 8
  • 36
  • 58
19
votes
5 answers

Binding UserControl Dependency Property and MVVM

I have a MainWindow containing a UserControl, both implemented in MVVM-pattern. The MainWindowVM has properties that I want to bind to properties in the UserControl1VM. But this doesn't work. Here's some code (the viewmodels use some kind of…
joerg
  • 717
  • 2
  • 8
  • 18
19
votes
1 answer

C# WPF Attached Properties - Error: "The property does not exist in XML namespace"

I need to create a new property to existing WPF controls (Groupbox, textbox, checkbox, etc), one that will storage its acess Level, therefore I've found out Attached Properties. I used as example this site…
18
votes
2 answers

Listen to DependencyProperty changed event and get the old value

I have the following code to subscribe to property changed event for VisiblePosition property of Column class: DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ColumnBase.VisiblePositionProperty, typeof(Column)); if…
sean717
  • 11,759
  • 20
  • 66
  • 90
18
votes
3 answers

Getting " was already registered by "" error in WPF

I have a user control in WPF that has a binding to a Dependency Property. When I try to compile the app, I get a "Property Name" was already registered by "ControlName" error, and the designer shows a "Cannot create an instance of "User Control"…
Ryan
  • 1,300
  • 12
  • 29