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

What are the main drawbacks of exposing a DependencyProperty via a static property instead of a static field? (F#)

I found out that F# 2.0 apparently doesn't support public static fields anymore, which makes impossible the standard way of implementing a DependencyProperty: public static readonly FooProperty = DependencyProperty.Register(...); // in C# I don't…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
10
votes
1 answer

XAML binding not working on dependency property?

I am trying (and failing) to do data binding on a dependency property in xaml. It works just fine when I use code behind, but not in xaml. The user control is simply a TextBlock that bind to the dependency property:
Oliver
  • 115
  • 1
  • 1
  • 6
10
votes
3 answers

Spring bean fields injection

Using Spring IoC allows to set bean properties exposed via setters: public class Bean { private String value; public void setValue(String value) { this.value = value; } } And the bean definition is:
Vladimir
  • 9,913
  • 4
  • 26
  • 37
10
votes
1 answer

WPF: Collection dependency property "is read-only and cannot be set from markup"

I am creating a user control to display a three-month calendar. The control is based on the WPF Calendar control (WPF Toolkit 2009-06), and I want to pass several of the Calendar's properties through to corresponding properties of my user control.…
David Veeneman
  • 18,912
  • 32
  • 122
  • 187
10
votes
1 answer

Knowing if a DependencyProperty has not been set in XAML

I have a control, which exposes a DP called PlacementTarget (it's bound to a child Popup FWIW). What I want to do is if PlacementTarget is not set in XAML, then (the control will) set it to the Window the control is in. When I say 'not set' I…
Jim W
  • 4,866
  • 1
  • 27
  • 43
10
votes
2 answers

Difference between CoreceValueCallback and ValidateValueCallback?

I know that CoerceValueCallback is used to correct a value and that ValidateValueCallback will return true or false. But my question is why we need ValidatevalueCallback? We can simply use CoerceValueCallback to validate (using if condition) and…
Ravuthasamy
  • 589
  • 1
  • 6
  • 16
10
votes
3 answers

Two-way binding in AvalonEdit doesn't work

I have used AvalonEdit in my project that is based on WPF and MVVM. After reading this post I created the following class: public class MvvmTextEditor : TextEditor, INotifyPropertyChanged { public static DependencyProperty DocumentTextProperty…
Naser Asadi
  • 1,153
  • 18
  • 35
10
votes
6 answers

Any way to un-register a WPF dependency property?

I'm running into an unusual problem in my unit tests. The class I'm testing creates a dependency property dynamically at runtime and the type of that dependency property can vary depending on the circumstances. While writing my unit tests, I need to…
Scott Bussinger
  • 2,767
  • 4
  • 28
  • 29
10
votes
2 answers

WPF bind usercontrol's property to parent's property

I have created a usercontrol, which has 2 dependency properties. I want to bind those dependency properties to the mainViewModel's property, so that whenever something gets changed in the user-control the parent's property gets updated. I tried,…
Ali
  • 309
  • 1
  • 5
  • 20
10
votes
3 answers

How to fire a command on double-click listbox item using MVVM?

I'm trying to launch an ICommand when the user double-clicks on a listbox item. Also, I'm trying to do this using the MVVM pattern. In this XAML, the key press "p" works perfectly. When I double click on the list box, the command never starts. …
James
  • 954
  • 2
  • 13
  • 27
10
votes
2 answers

Dependency property error

I am learning dependency properties. I read many posts & books but still I am not clear. The program shown below is which I wrote to learn. Some error in that, please help in resolving. I have questions. The main use of custom Dependency property…
SHRI
  • 2,406
  • 6
  • 32
  • 48
9
votes
2 answers

How does the WPF dependency property design save memory consumption?

I read this in the following link:- http://www.informit.com/articles/article.aspx?p=688529&seqNum=2 However, because GetValue and SetValue internally use an efficient sparse storage system and because IsDefaultProperty is a static field (rather…
teenup
  • 7,459
  • 13
  • 63
  • 122
9
votes
3 answers

How to create a Dependency property on an existing control?

I have been reading on Dependency properties for a few days and understand how they retrieve the value rather than to set/get them as in CLR properties. Feel free to correct me if I am wrong. From my understanding all WPF controls like a TextBlock,…
Houman
  • 64,245
  • 87
  • 278
  • 460
9
votes
2 answers

Is it appropriate to thrown an exception from CoerceValueCallback

Is it appropriate to throw an exception from a CoerceValueCallback if a given value is invalid or should only ValidateValueCallback be used for DP-value-validation?
HCL
  • 36,053
  • 27
  • 163
  • 213
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