WPF programmatically binding

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

WPF programmatically binding

Post by frank » Thu Nov 13, 2014 3:37 pm

Hi,
I'm trying to bind some properties in code instead of setting them on various locations. For some properties it works, for others it doesn't.

E.g. I can bind ChartBackground with

Code: Select all

_chart.SetBinding(LightningChartUltimate.ChartBackgroundProperty, new Binding { Converter = new Converters.ColorToFillConverter(), Path = new PropertyPath("BackgroundColor") });
But for the ViewXY-Properties I can't get it to work. E.g.

Code: Select all

_chart.SetBinding(ViewXY.GraphBackgroundProperty, new Binding { Converter = new Converters.ColorToFillConverter(), Path = new PropertyPath("GraphBackgroundColor") });
_chart.SetBinding(ViewXY.GraphBorderColorProperty, "GraphBackgroundColor");
Am I missing something?

Best regards,
Frank

ArctionJari

Re: WPF programmatically binding

Post by ArctionJari » Fri Nov 14, 2014 8:50 am

Use this instead:

Code: Select all

			Binding b = new Binding();
			b.Source = this;
			b.Converter = new FillConverter();
			b.Path = new PropertyPath("GraphBackgroundColor");

			BindingOperations.SetBinding(_chart.ViewXY, ViewXY.GraphBackgroundProperty, b);

			Binding b2 = new Binding();
			b2.Source = this;
			b2.Path = new PropertyPath("GraphBackgroundColor");

			BindingOperations.SetBinding(_chart.ViewXY, ViewXY.GraphBorderColorProperty, b2);

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: WPF programmatically binding

Post by frank » Fri Nov 14, 2014 9:21 am

Thanks! It works.

Post Reply