Reputation: 11
I am creating infragistics wpf grid at runtime.
in FieldLayoutInitialized i am creating unbound fields.
one sample unbound field is
UnboundField field = new UnboundField();
field.Name= "Testfield";
field.BindingPath = "Binding path";
FieldLayout fieldLayout;
fieldLayout.Fields.Add(field)
But my requirement is i have a field which is calculated one so for that i created converter. converter will return sum of two values.
A3 = A1+A2;
If it is from XAML file we can write like
<Textbox.Value>
<MultiBinding Converter="{StaticResource ConvertnameClass}" Mode="OneWay">
<Binding Path="A1"/>
<Binding Path="A2"/>
</MultiBinding>
</Textbox.Value>.
field.Converter = coverter class object; field.ConverterParameter = ???;
if it is single binding we can send the field.BindingPath = "class prop value";
how can i send multiple binding values to converter from code behind when it is creating run time.
please help me out.
Upvotes: 1
Views: 1480
Reputation: 14611
here is a sample that creates a multibinding in code behind
put this at your FieldLayoutInitialized event
private void FieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) {
var fieldlayout = e.FieldLayout;
UnboundField field = new UnboundField();
field.Name = "Testfield";
fieldlayout.Fields.Add(field);
var multiBinding = new MultiBinding();
multiBinding.Mode = BindingMode.OneWay;
multiBinding.Converter = new MultiBindingConverter(); // implement IMultiValueConverter
multiBinding.Bindings.Add(new Binding() { Path = new PropertyPath("A1"), Mode = BindingMode.OneWay });
multiBinding.Bindings.Add(new Binding() { Path = new PropertyPath("A2"), Mode = BindingMode.OneWay });
field.Binding = multiBinding;
}
probably you must specify Source or RelativeSource for the two bindings
hope this helps (i used the 11.1 libs)
Upvotes: 2