Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default settings for bound WPF DependencyProperty

I've created a custom user control named MyCustomComboBox. Everywhere in the application I put it I do the following:

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

MyCustomComboxBox has the dependency property Foo, I have some validation and other logic in the combobox which is the very reason why I wrapped it up in a custom control.

The custom combobox is included another user control which also has a Foo property, which the combobox's is bound to.

But I also have to set UpdateSourceTrigger and Mode, I would like to somehow specify that those are the default values when binding to that DependencyProperty. Can it be done?

like image 852
Mizipzor Avatar asked Jul 11 '26 16:07

Mizipzor


1 Answers

The default BindingMode can 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 for the update source trigger.

like image 98
Kent Boogaart Avatar answered Jul 13 '26 15:07

Kent Boogaart