Hi,
I implemented the new Application.Current.RequestedThemeChanged event to detect when the app needs to change the style.
So I added following to the App.xml.cs file
public App()
{
...
Application.Current.RequestedThemeChanged += (s, a) => { SetTheme(a.RequestedTheme); };
}
The event, once triggered, is performing following action.
private void SetTheme(OSAppTheme appTheme)
{
try
{
switch (appTheme)
{
case OSAppTheme.Dark:
Current.Resources = new DarkTheme();
break;
case OSAppTheme.Light:
Current.Resources = new LightTheme();
break;
case OSAppTheme.Unspecified:
Current.Resources = new LightTheme();
break;
}
}
catch(Exception exc)
{
Debug.WriteLine($"Error while switching theme {exc.Message}");
}
}
So, now when I'm leaving the page where the SfCircularGauge is on (Shell navigation to another page), and send the app in background, an exception is caused.
Cannot access a disposed object.
Object name: 'SFCircularScale'.
I'm testing it on iOS with a simulator, however it also happens on real iOS devices. That's because I added a try {} catch block to it.
Is this a problem from Xamarin or from your control? Just seems to happen with the SfCircularGauge.
Both are used at this page.
This is how my XAML for the scale is looking like:
<gauge:SfCircularGauge.Scales>
<gauge:Scale
LabelFontSize = "{OnPlatform Android=10, iOS=12, Default=10 }"
LabelFont="{StaticResource Montserrat-Regular}"
ShowRim = "False" LabelOffset = "0.85"
StartValue = "0" EndValue = "{Binding LimitExtruder}" Interval = "{Binding ExtruderInterval}"
RimThickness="28"
MinorTicksPerInterval ="4"
LabelColor="{DynamicResource Gray-Black}"
>
<gauge:Scale.Pointers>
<gauge:NeedlePointer Value="{Binding SelectedExtruder.TempRead}" Color="{DynamicResource Gray-Black}"
KnobColor="{DynamicResource Gray-Black}" KnobStrokeColor="{DynamicResource Gray-Black}"/>
<gauge:RangePointer Value="{Binding SelectedExtruder.TempRead}" Color="{DynamicResource PrimaryColor}"
RangeCap="Both"
/>
<gauge:MarkerPointer Value="{Binding SetExtruderTemp}" Color="{DynamicResource Red}"/>
</gauge:Scale.Pointers>
<gauge:Scale.MajorTickSettings>
<gauge:TickSettings Thickness="1" EndOffset="0.73" StartOffset="0.65" Length="8" Color="{DynamicResource Gray-Black}"/>
</gauge:Scale.MajorTickSettings>
<gauge:Scale.MinorTickSettings>
<gauge:TickSettings Thickness="0.7" EndOffset="0.69" StartOffset="0.65" Color="{DynamicResource Gray-Black}"/>
</gauge:Scale.MinorTickSettings>
<gauge:Scale.Ranges>
<gauge:Range StartValue = "0" EndValue = "{Binding LimitExtruder}" Thickness = "18" Offset = "0.6">
<gauge:Range.GradientStops>
<gauge:GaugeGradientStop Value="0" Color="{StaticResource TempLow}"/>
<gauge:GaugeGradientStop Value="{Binding MiddleExtruder}" Color="{StaticResource TempMiddle}"/>
<gauge:GaugeGradientStop Value="{Binding LimitExtruder}" Color="{StaticResource TempHigh}"/>
</gauge:Range.GradientStops>
</gauge:Range>
</gauge:Scale.Ranges>
</gauge:Scale>
</gauge:SfCircularGauge.Scales>
Thanks for helping out!