Mizipzor
Mizipzor

Reputation: 52371

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?

Upvotes: 3

Views: 3142

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178770

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.

Upvotes: 4

Related Questions