Twoway-bind view’s DependencyProperty to viewmodel’s property?

If you want to do it in XAML, you could try using styles to achieve that. Here’s an example: <UserControl x:Class=”MyModule.MyView” xmlns:local=”clr-namespace:MyModule”> <UserControl.Resources> <Style TargetType=”local:MyView”> <Setter Property=”MyViewProperty” Value=”{Binding MyViewModelProperty, Mode=TwoWay}”/> </Style> </UserControl.Resources> <!– content –> </UserControl> In your case both MyViewProperty and MyViewModelProperty would be named MyProperty but I used different names just to be … Read more

What is the difference between Property and Dependency Property

Dependency properties and standard properties are quite different. The key features delivered by dependency properties are support for binding and animation. If you want to assign a value to a property using a Binding or template binding that property needs to be a dependency property. When animating a property the a dependency property can track … Read more

What’s the difference between Dependency Property SetValue() & SetCurrentValue()

The MSDN link you provided says it quite well: This method is used by a component that programmatically sets the value of one of its own properties without disabling an application’s declared use of the property. The SetCurrentValue method changes the effective value of the property, but existing triggers, data bindings, and styles will continue … Read more

What is a dependency property?

The only explanation I found helpful and well written is this one: http://www.wpftutorial.net/dependencyproperties.html Basically, DependencyProperties differ from regular properties in that they’re not just setters / getters for fields in the class, but they retrieve their actual values dynamically during runtime. The SetValue() method of DPs is pretty straightforward and sets the local value of … Read more

What’s the difference between a dependency property and an attached property in WPF?

Attached properties are a type of dependency property. The difference is in how they’re used. With an attached property, the property is defined on a class that isn’t the same class for which it’s being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row – you apply this to a control … Read more

How to correctly bind to a dependency property of a usercontrol in a MVVM framework

That is one of the many reasons you should never set the DataContext directly from the UserControl itself. When you do so, you can no longer use any other DataContext with it because the UserControl’s DataContext is hardcoded to an instance that only the UserControl has access to, which kind of defeats one of WPF’s … Read more

Listen to changes of dependency property

This method is definitely missing here: DependencyPropertyDescriptor .FromProperty(RadioButton.IsCheckedProperty, typeof(RadioButton)) .AddValueChanged(radioButton, (s,e) => { /* … */ }); Caution: Because DependencyPropertyDescriptor has a static list of all handlers in application every object referenced in those handlers will leak if the handler is not eventually removed. (It does not work like common events on instance objects.) Always … Read more

DependencyProperty getter/setter not being called

I would suggest not to use ObservableCollection as the type of an Items dependency property. The reason for having an ObservableCollection here (I guess) is to enable the UserControl to attach a CollectionChanged handler when the property value is assigned. But ObservableCollection is too specific. The approach in WPF (e.g. in ItemsControl.ItemsSource) is to define … Read more

tech