Problem in switching dynamically the colorTheme property
Posted: Mon Nov 02, 2020 9:09 am
In my application users can switch theme between dark and light at runtime. So I would like that also the charts follow the same behavior, however I'm struggling in achieving this.
I'm using the semi-bindable API, so I have a xaml like this:
However this approach do not work. When ColorTheme binding is present I get a null reference exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Arction.Wpf.SemibindableCharting.LightningChartUltimate.AQC(ColorTheme A)
at Arction.Wpf.SemibindableCharting.LightningChartUltimate.ColorThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
A more complete stacktrace produced by ChartChartMessage event can be found at: https://pastebin.com/ZQMq5qnG
So I then followed the approach described in this topic: viewtopic.php?f=16&t=653&p=2439&hilit=colorTheme#p2439
However it does not work very well as the result is a partial theme change as you can see in the attached screenshot. It seems that some part of the chart are not rendered with the correct theme.
Thanks in advance.
I'm using the semi-bindable API, so I have a xaml like this:
Code: Select all
<lcusb:LightningChartUltimate
ColorTheme="{Binding Theme.Value}"
Title="{Binding ChartTitle.Value}"
ActiveView="{Binding ViewType.Value}">
...
</lcusb:LightningChartUltimate>
System.NullReferenceException: Object reference not set to an instance of an object.
at Arction.Wpf.SemibindableCharting.LightningChartUltimate.AQC(ColorTheme A)
at Arction.Wpf.SemibindableCharting.LightningChartUltimate.ColorThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
A more complete stacktrace produced by ChartChartMessage event can be found at: https://pastebin.com/ZQMq5qnG
So I then followed the approach described in this topic: viewtopic.php?f=16&t=653&p=2439&hilit=colorTheme#p2439
However it does not work very well as the result is a partial theme change as you can see in the attached screenshot. It seems that some part of the chart are not rendered with the correct theme.
Thanks in advance.