WPF UserControl Dependency Property Setter not starting

Possible duplicate:
WPF: XAML property declarations are not set via Setters?

I am stuck in a seemingly stupid problem.

I have a user control, MyControl.xaml and MyControl.xaml.cs defines a public dependency property:

public static readonly DependencyProperty VisibleItemsProperty = DependencyProperty.Register("VisibleItems", typeof(object), typeof(MyControl)); public object VisibleItems { get { return (object)GetValue(VisibleItemsProperty); } set { SetValue(VisibleItemsProperty, value); } } 

In another view of SomeOtherViewA, I declare my control:

 <cc:MyControl VisibleItems="{Binding VisibleTables}" /> 

VisibleTables is a dependency property in SomeOtherViewModelA viewmodel.

I know that VisibleTables returns values ​​because it is connected to other controls in SomeOtherViewA (like ListBox) and they work fine.

For some reason, the dependency property inside my user control is never set. Am I missing something?

+4
source share
1 answer

I think I just found a duplicate .

Also about this on MSDN :

The WPF XAML processor uses the property system property dependency methods when loading binary XAML and processing attributes that have dependency properties. This effectively circumvents property wrappers. When you implement custom dependency properties, you should explain this behavior and should avoid placing any other code in your property wrapper other than the GetValue and SetValue property system methods.

( SetValue is called directly, these shell properties are just available for convenience in the code)

+4
source

Source: https://habr.com/ru/post/1347836/


All Articles