views:

106

answers:

1

Ive 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?

+1  A: 

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.

HTH,
Kent

Kent Boogaart
There is a way to set the default update source trigger as well; just found this (http://stackoverflow.com/questions/1094509/wpf-define-bindings-default/1094744#1094744) which is essentially a duplicate of my question. Much nice extra information there.
mizipzor
Cool - I missed that in the docs.
Kent Boogaart