Questions tagged [dependencyobject]

The DependencyObject class enables Windows Presentation Foundation (WPF) property system services on its many derived classes.

The property system's primary function is to compute the values of properties, and to provide system notification about values that have changed. Another key class that participates in the property system is DependencyProperty. DependencyProperty enables the registration of dependency properties into the property system, and provides identification and information about each dependency property, whereas DependencyObject as a base class enables objects to use the dependency properties.

DependencyObject services and characteristics include the following:

  • Dependency property hosting support. You register a dependency property by calling the Register method, and storing the method's return value as a public static field in your class.

  • Attached property hosting support. You register an attached property by calling the RegisterAttached method, and storing the method's return value as a public static read-only field in your class. (There are also additional member requirements; note that this represents a WPF specific implementation for attached properties. For details, see Attached Properties Overview.) Your attached property can then be set on any class that derives from DependencyObject.

  • Get, set, and clear utility methods for values of any dependency properties that exist on the DependencyObject.

  • Metadata, coerce value support, property changed notification, and override callbacks for dependency properties or attached properties. Also, the DependencyObject class facilitates the per-owner property metadata for a dependency property.

  • A common base class for classes derived from ContentElement, Freezable, or Visual. (UIElement, another base element class, has a class hierarchy that includes Visual.)

100 questions
3
votes
2 answers

How to get the Window hosting a UIElement instance

I'm trying to get the Window instance which is hosting a UIElement instance in WinUI 3. There's a helper method in the Window class in .NET (see this thread) but i cannot find something similar for C++/WinRT. I tried VisualTreeHelper as some…
ridilculous
  • 624
  • 3
  • 16
3
votes
1 answer

How to bind a property to the property of another class (with no UI Control)?

I'm spending hours on Google researching my simple Task. I'm trying to do bind my variable TestString to TestClass.MeinString. If I click on the button "tb_tbBinding" TestString and TestClass.MyString should stay the same value. Relevant…
3
votes
1 answer

Binding to a collection of DependencyObjects in Silverlight 4

As of Silverlight 4 it is possible to data bind against a DependencyObject (instead of a Framework element in previous versions). So far so good, but how do I bind agains a collection of DependencyObjects. The DataContext is not passed from the…
3
votes
0 answers

Creating an Intelligent DocumentPaginator which is able to cut a Compex UIElement in Pages for printing

I'm currently working an DocumentPaginator which allow me to do: PrintDialog printDialog = new PrintDialog(); if(printDialog.ShowDialog()== true) { var cp = new ControlPaginator(myUIElement, new Size(printDialog.PrintableAreaWidth,…
WiiMaxx
  • 5,322
  • 8
  • 51
  • 89
3
votes
1 answer

Using Dependency object for color animation WP8

I'm using a button where I've shaped it, in its ControlTemplate. I've also added a storyboard in the controlTemplate. The storyboard changes the boarder of the element in my controlTemplate. I access this from the code behind and activate it, the…
3
votes
1 answer

Dependency Property vs INotifyPropertyChanged in ViewModel for Windows 8 application

I have created blank C#/XAML Windows 8 application. Add simple XAML code:
2
votes
1 answer

Is it possible to find out the assembly and file containing a DependencyObject?

I am currently working on a little localization framework for WPF (don't even think about pointing me to locBAML...) and wondered if it was possible to find out the containing assembly of a specified DependencyObject. For example: I have a normal…
chrischu
  • 3,047
  • 3
  • 27
  • 44
2
votes
1 answer

Create a DependencyObject that "accepts" direct content

I'm creating a custom time that should be used in an empty XAML file:
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
2
votes
2 answers

How do you unit test Silverlight ValueConverters that create DependencyObjects

I have a Silverlight ValueConverter that should take an enum and convert it to a Brush. Something like this simplified example: public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var brush = new…
Peter
  • 13,733
  • 11
  • 75
  • 122
2
votes
1 answer

List properties of a DependencyObject?

I got a collection of custom DependencyObjects that I created. But I think that it doesn't matter wherever the DependencyObject comes from. The thing is that I'd like the list its properties but when I'm looking at the C#doc for DependencyObject I…
Guillaume Slashy
  • 3,554
  • 8
  • 43
  • 68
2
votes
1 answer

Custom design time visibility attribute in WPF

I have a complex window with various controls that are visible or collapsed based on bool values. I want to add a custom attribute to show all of these controls during design time. My implementation of the attribute looks like this: public static…
gedvrk
  • 31
  • 5
2
votes
1 answer

Simple databinding IN CODE to a DependencyProperty

My apologies as this is simplistic enough I know the question's been answered but in 30 or so pages, I've yet to find the boiled down problem I'm trying to solve. I'm not yet well practiced in SL and trying a simple version of attempting to write a…
John Spiegel
  • 1,861
  • 3
  • 24
  • 39
2
votes
1 answer

DependencyObject does not handle equality on object properties well

I was confronted with a StackOverflowException that made me discover that DependencyObject does not handle equality correctly ?! When the DependencyProperty is of Type Object it will allways use Reference.Equals. This causes to fire PropertyChanged…
CSharpie
  • 9,195
  • 4
  • 44
  • 71
2
votes
2 answers

Casting error for UIElement on runtime

I get runtime error when I do this. I have this class: public abstract class AnnObject : DependencyObject and when I do this it compiles fine, but throws a runtime error... AnnObject aa; var b = (DependencyObject)aa; var c = (UIElement)b; The…
VoodooChild
  • 9,776
  • 8
  • 66
  • 99
2
votes
1 answer

How to expose xaml properties?

I created a ComboBox subclass and added my functionality. Now I want to expose external properties of the TextBox for example: Is this possible, I maybe didn't choose…