shabi
shabi

Reputation:

setting control property in cs file

I want to set the control binding property "updatesource=Explicit" in cs file (dynamically) not in UI end. Please help me how can i do this?

Upvotes: 0

Views: 151

Answers (3)

gimalay
gimalay

Reputation: 493

it works :)

this.GetBindingExpression(SomeProperty).ParentBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

Upvotes: 1

Trainee4Life
Trainee4Life

Reputation: 2273

I tested it and it works. :-) The code remains the same as Gimalay's.

BindingExpression bindingExpr = this.textBox1.GetBindingExpression(TextBox.TextProperty);
bindingExpr.ParentBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

Upvotes: 0

Drew Noakes
Drew Noakes

Reputation: 310822

Are you creating the binding in code manually? If so you can just set it like any other property:

var binding = new Binding("BindingPath")
{
    Source = myDataObject,
    UpdateSourceTrigger = UpdateSourceTrigger.Explicit
}    
textBlock.SetBinding(TextBlock.TextProperty, binding);

More information here.

Upvotes: 0

Related Questions