Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent of DependencyObjectCollection<T> for WPF .NET4.0?

The class allows the propagations of data context from the collection to its members. But it is only for SilverLight.

More info for DepedencyObjectCollection can be found from this post.

If the equivalent doesn't exist, what's the necessary steps required to create one?

I observe the desire behavior from the RowDefinitionCollection class. But I couldn't figure out its implementation.

thanks

like image 429
Rushui Guan Avatar asked Jan 08 '13 22:01

Rushui Guan


People also ask

What is DependencyObject WPF?

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.

When should I use dependency properties in WPF?

Dependency properties are used when you want data binding in a UserControl , and is the standard method of data binding for the WPF Framework controls. DPs have slightly better binding performance, and everything is provided to you when inside a UserControl to implement them.

What is a DependencyProperty?

A Dependency Property is a property whose value depends on the external sources, such as animation, data binding, styles, or visual tree inheritance. Not only this, but a Dependency Property also has the built-in feature of providing notification when the property has changed, data binding and styling.

What is attached property in WPF?

An attached property is a Extensible Application Markup Language (XAML) concept. Attached properties enable extra property/value pairs to be set on any XAML element that derives from DependencyObject, even though the element doesn't define those extra properties in its object model.


1 Answers

The short answer is NO.

But I no longer think it is the correct implementation anyway. I end up using a collection of FrameworkElement and add them into the LogicalChildren of the custom control. By doing so, DataContext are passed on to the FrameworkElement naturally and everything works as expected.

It seems that that's how RowDefinition class is implemented in .NET 4.0. However, Silverlight version of RowDefinition is derived from DependencyObject directly. The MSDN document shows Silverlight documentation by default and misdirected me to the older and incorrect approach.

like image 66
Rushui Guan Avatar answered Oct 19 '22 18:10

Rushui Guan