Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I set the converter binding in the C# code?

I am newbie in WPF and now I am using a 3rd party lib xamChart in my project

previously in the XAML i have a Chart and its axis has a Unit which is a int property and I have

Unit="{Binding NextStartRow, Converter={StaticResource UnitConverter}}"

This works perfectly, but now I need to create the chart in the runtime through the code behind. How can I do that in C#? and FYI all the axis.Unit.xxx in the c# code do not have the thing I want, Please help, thank you very much in advance, any suggestion is much appreciated!

FYI code snippet in of xaml

<igCA:Axis AxisType="PrimaryX" AutoRange="True"  
           Unit="{Binding AnotherIntegerProperty, Converter={StaticResource UnitConverter}}">
like image 588
Ted Xu Avatar asked Jul 28 '11 10:07

Ted Xu


People also ask

How to bind a parameter to a converter?

You can't bind a converter parameter because it's not a dependency property but you could use multi binding to do that: Lead Software Engineer -... Efforts may fail but don't fail to take effort -------------- sidd What markup do you have, what code for your converter and what is the expected result? Hope that helps.

How do I use inttoboolconverter in a data binding?

The following example demonstrates how to use this value converter in a data binding: In this example, the IntToBoolConverter is instantiated in the page's resource dictionary. It's then referenced with a StaticResource markup extension to set the Converter property in two data bindings.

What is the use of convert method in data binding?

This class becomes part of the data binding. The Convert method is called when data moves from the source to the target in OneWay or TwoWay bindings. The value parameter is the object or value from the data-binding source. The method must return a value of the type of the data-binding target.

Is converterparameter a dependency property or bindable?

My understanding is : 'ConverterParameter is not a dependency property and it's not bindable'. {"A 'Binding' cannot be set on the 'ConverterParameter' property of type 'Binding'.


1 Answers

Try this by adjusting anything is not correct as you missed to specify:

myXamChart.SetBinding(
  Unit,
  new Binding("AnotherIntegerProperty")
  {
    Converter = new UnitConverter()
  });

Cheers

like image 182
Mario Vernari Avatar answered Oct 21 '22 06:10

Mario Vernari