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

Is it possible to force a binding based on a DependencyProperty to re-evaluate programmatically?

NOTE: Before reading the subject and instantly marking this as a duplicate, please read the entire question to understand what we are after. The other questions which describe getting the BindingExpression, then calling UpdateTarget() method does…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
7
votes
1 answer

Dependency Property in F# Default Value does not match

I am trying to convert a C# Dependency Property that limits the maximum length of text entered into a ComboBox to F#. The program is a MVVM program that uses F# for the model and viewmodel, and C# for the view. the working C# code is this: public…
Mark W
  • 811
  • 2
  • 11
  • 17
7
votes
2 answers

WPF - Binding an ObservableCollection Dependency Property within a UserControl

I have a control class DragGrid : Grid { ... } which inherits from the original grid and enables dragging and resizing its child elements. I need to bind a custom DP named WorkItemsProperty to an observable collection of type WorkItem…
John
  • 3,591
  • 8
  • 44
  • 72
7
votes
1 answer

Simple Injector usage for generic command handler

The interfaces,commands and command handler set up as per instructions in Simpleinjector wiki. public interface ICommand { string Name { get; set; } } public class Command1 : ICommand { public string Name { get; set; } } public class…
Aravind
  • 4,125
  • 1
  • 28
  • 39
7
votes
1 answer

Create Dependency Properties for setting Custom EventHandlers in XAML

i want to do add custom event handlers to default framework elements using DependencyProperties. Something like the following: ... Here is the code behind for the control that contains the…
Juve
  • 10,584
  • 14
  • 63
  • 90
7
votes
3 answers

DependencyProperty Registration in ViewModel

I am finding a lot of discussions about ViewModels and their Properties that compare two approches: implementation of INotifyPropertyChanged or implementation via Dependency Properties. While I am doing INotifyPropertyChanged a lot (and it's…
joerg
  • 717
  • 2
  • 8
  • 18
7
votes
3 answers

Exposing Child Control Dependency Properties for Binding in WPF

I have a very simple UserControl called CustomTextBox with this XAML: Now when I use CustomTextBox and want to do binding to…
Libor
  • 3,285
  • 1
  • 33
  • 41
7
votes
4 answers

WPF ReadOnly Dependency Properties using MVVM

I've recently overridden the DevXpress WPF grid to give myself a SelectedObject property that I can access from my loosely bound ViewModel. I've made a SelectedObject dependency property and have it bound OneWayToSource in my XAML. Everthing works…
Andy Clarke
  • 3,234
  • 5
  • 39
  • 66
7
votes
2 answers

MVVM + UserControl + Dependency Property

Alright, this is somewhat related to this question: WPF Printing multiple pages from a single View Model I tried to follow the advice given there but now I am stuck. My application uses a MainView.xaml and the appropriate MainViewViewModel.cs, I am…
Tom L.
  • 932
  • 2
  • 9
  • 30
7
votes
2 answers

Unity Static Property Injection

I have two classes, one which sets up the container by registering types and one which contains a static property which I want to inject into. My issue is the property is never set by injection so when I call a method on it, the property is always…
7
votes
2 answers

WPF Binding to UserControl Custom DependencyProperty

I have a custom UserControl called SongDescription:
gs_vlad
  • 1,409
  • 4
  • 15
  • 29
7
votes
1 answer

WPF - Can List be used as a dependencyProperty

I have a simple search text box. This text box acts as a filter. I've now copied/pasted the code for the 5th time and enough is enough. Time for a custom control. left and right brackets have been replaced with () My custom control will be…
tronious
  • 1,547
  • 2
  • 28
  • 45
7
votes
2 answers

Dependency property in app.xaml.cs

I am new to WPF and the below question may look silly for many, please pardon me. How can I create a dependency property in app.xaml.cs? Actually, I tried to created it. The below code, public static DependencyProperty TempProperty = …
Vijay
  • 2,133
  • 4
  • 27
  • 40
7
votes
5 answers

MultiTrigger: Condition Binding to DependencyProperty doesn't work

I have a custom button MainMenuButton of type UserControl and atm I'm styling it. Now I wanted to implement a MultiTrigger to only change the appearance of the button if two conditions are met. The first condition is if IsMouseOver == true. I simply…
TorbenJ
  • 4,462
  • 11
  • 47
  • 84
6
votes
3 answers

What is the relationship between INotifyPropertyChanged and DependencyProperty?

I'm building a simple UserControl example with DependencyProperties so that the properties of the control can be changed in XAML (code below). But of course in my application I don't want this control to have tightly-coupled code-behind, but instead…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047