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

Chaining DependencyProperties

Let's say I have a custom control which wraps another control (for example MyCustomButton). I expose a property Content, which wraps the inner control: public object Content { get { return innerControl.Content; } set {…
Jeff
  • 35,755
  • 15
  • 108
  • 220
6
votes
4 answers

Cannot pass/bind command to WPF user control

I'm trying to pass a command to an element in a WPF user control.
David
  • 3,736
  • 8
  • 33
  • 52
6
votes
1 answer

WPF Custom Control: DependencyProperty of Collection type

I have a CustomControl which contains a ListBox:
Aris
  • 181
  • 3
  • 13
6
votes
4 answers

How is the WPF property system economical?

It is said that the designers of WPF have made it economical or higher performance. Can someone please explain with an example of what happens under the hood that makes the WPF property system more economical?
paseena
  • 4,207
  • 6
  • 32
  • 51
6
votes
2 answers

Logically combine dependency properties

I'm using C# 4.0 and have created a DependencyObject MyView. In MyView, I have two DependencyProperties, PropA and PropB, both are booleans. I want a third DependencyProperty, PropC, also a bool, and simply put, should always give me (PropA ||…
JoeSharp
  • 405
  • 1
  • 7
  • 16
6
votes
2 answers

How to add a DependencyProperty to a Button?

I'm basically just trying to add a couple properties to a button to store some extra information to be used later. My choice to do this instead of creating a UserControl based on a Button was solely because it seemed like less code. I've followed…
Ben
  • 63
  • 1
  • 3
6
votes
2 answers

WPF Binding to variable / DependencyProperty

I'm playing around with WPF Binding and variables. Apparently one can only bind DependencyProperties. I have come up with the following, which works perfectly fine: The code-behind file: public partial class MainWindow : Window { public…
PeterE
  • 5,715
  • 5
  • 29
  • 51
6
votes
1 answer

Difference between Xamarin.Forms BindableProperty and WPF DependencyProperty

Having a lot of experience in the WPF developement I'm now trying to create my first Xamarin.Forms application. I recognized that there is some equivalent to the WPF DependencyProperty called BindableProperty. They seem to be quite the same, so my…
6
votes
2 answers

C#: Extending from more than 1 class

Suppose I have a ViewModel TabViewModel that Extends ObservableObject the class for ViewModels in the MVVM Foundation Framework. Then I also have a EditorTabViewModel that extends TabViewModel, Now I need to extend DependencyObject to implement…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
6
votes
1 answer

Arranging collection items in a grid

I would like to arrange items of a collection in a grid with a specific number of columns and rows (say 4x6). Each item exposes the dependency properties (integer) X and Y and should be placed in the relevant cell of the grid. Note that the…
user458795
6
votes
2 answers

DependencyProperty of Type Delegate

I have created an attached behavior that is used to execute a Delegate of type Func when the behavior is invoked. Below is the dependancy property definition. public static readonly DependencyProperty SendToDetailBehaviorProperty =…
6
votes
2 answers

Why is a custom property in a UserControl not set when the control is used in a DataTemplate?

I have a UserControl that has a custom DependencyProperty. When I use the UserControl from inside a DataTemplate, I cannot set the value of the DependencyProperty. If I use the UserControl directly in a window, then the DependencyProperty works…
Carlos
  • 915
  • 1
  • 7
  • 11
6
votes
1 answer

XAML: How can I bind a DependencyProperty to a C# property of the same name on a different object?

Using: Visual Studio Community Edition 2015 .Net 4.0 I've implemented this answer, producing my own CheckBox class complete with an IsChecked DependencyProperty. That property is backed by the IsChecked property on the WPF CheckBox, or would be if…
Grault
  • 974
  • 12
  • 31
6
votes
6 answers

WPF DependencyProperties

I have just realized I've been coercing binding/dependency properties and not really fundamentally understanding the concept. Heres the dependency property: public string Problem { get { return (string)GetValue(ProblemProperty); } set {…
Dave
  • 291
  • 1
  • 3
  • 8
6
votes
2 answers

WPF Exposing a calculated property for binding (as DependencyProperty)

I have a complex WPF control that for some reasons (ie. performance) is not using dependency properties but simple C# properties (at least at the top level these are exposed as properties). The goal is to make it possible to bind to some of those…
kubal5003
  • 7,186
  • 8
  • 52
  • 90