Default Settings for Associated WPF DependencyProperty

I created a custom control named MyCustomComboBox. Anywhere in the application, I do the following:

    <Widgets:MyCustomComboBox
        Foo="{Binding Foo, 
            UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" /> 

MyCustomComboxBox has a dependency property Foo, I have some checks and other logic in combobox, and for this reason I wrapped it in a user control.

A custom combobox includes another user control that also has the property Foothat the combo box is associated with.

But I also need to install UpdateSourceTriggerand Mode, I would like to somehow indicate that they are the default values ​​when binding to this DependencyProperty. It can be done?

+3
source share
1 answer

The default value BindingModecan be specified in the dependency property metadata:

public static readonly DependencyProperty FooProperty = DependencyProperty.Register(
    "Foo",
    typeof(string),
    typeof(MyCustomComboBox),
    new FrameworkPropertyMetadata(
        null,
        FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);

However, to my knowledge, there is no way to provide a default value for an update source trigger.

+3
source

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


All Articles