Can't set Title color after switching ColorTheme

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Arction_LasseP

magla
Posts: 3
Joined: Mon Jan 19, 2015 9:22 am

Can't set Title color after switching ColorTheme

Post by magla » Thu Mar 19, 2020 11:09 am

I have set the ColorTheme of the chart in code-behind, and then the color I set for my AxisYTitle in xaml is ignored.

Trying to set the text Color after changing the color theme also has no effect. Changing the Fill however works:

Code: Select all

Chart.ColorTheme = ColorTheme.LightGray;

Chart.ViewXY.YAxes[0].Title.Color = Colors.DeepPink; // This has no effect when ColorTheme is set above
Chart.ViewXY.YAxes[0].Title.Fill.Color = Colors.Gold; // But this works
(I don't actually want these specific colors, they are just to make it apparent that something happens)

Without the change of ColorTheme the change of text color takes effect.

Is this a bug, or am I missing something?

A second question is that I would prefer being able to set colors directly in xaml, is that possible to do and also change ColorTheme?

Using version 8.5.1.1 semi-bindable, on .NET Core 3.1.

Edit: Some additional info is that there actually are two charts in the same user control, and ColorTheme is changed on both.
Edit 2: As I change things while developing sometimes the color actually gets set, but the pattern to it is not clear to me. Could it be some sort of race condition?

I also have the same problem with the Fill color for an AnnotationXY. Whether I set it in xaml or code-behind after changing ColorTheme, the color is simply ignored. I can however for example set the Fill color for instances of AxisYTitle and AxisXTitle used as AxisY.Units respectively AxisX.Units.

Thanks,
Magnus
Last edited by magla on Fri Mar 20, 2020 1:31 pm, edited 1 time in total.

ArctionKestutis
Posts: 383
Joined: Mon Mar 14, 2016 9:22 am

Re: Can't set Title color after switching ColorTheme

Post by ArctionKestutis » Fri Mar 20, 2020 11:06 am

Hello,

Setting the ColorTheme will override majority of the object colors in the created chart. It is recommended first set the ColorTheme and then modify the object colors. Color theme (call) internally changes default colors for 50+ objects (e.g. background, Title, Axis, Ticks, Legendbox etc.).

You should set ColorTheme and any desired addition in the code. Typically calling the method with all new settings is most transparent approach.
In our Demo App such modification is done with

Code: Select all

	ExampleUtils.SetDarkFlatStyle(_chart);
Other reason for strange pattern could be Sharing objects between other objects. Sharing objects between other objects in the same chart, or other chart instances, is not allowed. Check User's Manual corresponding chapter 27.1.

Hope this helps.

magla
Posts: 3
Joined: Mon Jan 19, 2015 9:22 am

Re: Can't set Title color after switching ColorTheme

Post by magla » Fri Mar 20, 2020 1:44 pm

Yes, I am aware of both of these pitfalls. The axes are declared inline in the chart in xaml, and I don't move them in code-behind. As shown in the code snippet, I also update the title-color after setting the ColorTheme.

I also have the same issue with an AnnotationXY, where I can't change the Fill-color (I would like to have it semi-transparent).

Changing the colors works fine if I skip changing the ColorTheme.
The code is in the constructor, is that the right place for it?

ArctionKestutis
Posts: 383
Joined: Mon Mar 14, 2016 9:22 am

Re: Can't set Title color after switching ColorTheme

Post by ArctionKestutis » Thu Mar 26, 2020 2:51 pm

It is possible to change properties at any time: during construction of Chart, after RangeChange or mouse click event etc.
However, in this context, you need to change ColorTheme as early as possible, because it overwrites many default internal colors. This will allow to modify specific properties afterwards.
If you find that something is not set properly, then you may need to wait for Chart to render once with new ColorTheme. For example, Chart.AfterRendering event could be useful there.

All the best.