- Home
- Forum
- Xamarin.Forms
- Issue with SelectionIndicatorSettings.Color Binding causing crash
Issue with SelectionIndicatorSettings.Color Binding causing crash
I have several similar pages, each page using a different instance of the same ViewModel. These pages are stored in an ObservableCollection. Each of these pages has a Segmented control looking and acting like a switch:
And Methods
<sfCheckbox:SfSegmentedControl Color="{Binding SegmentControlColor}"
x:Name="segmentedControl" CornerRadius="13"
SegmentHeight="25"
SegmentWidth="20"
BorderThickness="0"
WidthRequest="25"
VisibleSegmentsCount="2"
ItemsSource="{Binding SegmentedList}"
FontIconFontFamily="{StaticResource fontfamily}"
SegmentPadding="0"
SegmentCornerRadius="13"
DisplayMode="Image">
<sfCheckbox:SfSegmentedControl.Behaviors>
<behaviors:EventToCommandBehavior EventName="SelectionChanged" Command="{Binding ChecklistStateChangedCommand}" Converter="{StaticResource SelectionChangedEventArgsConverter}"/>
</sfCheckbox:SfSegmentedControl.Behaviors>
<sfCheckbox:SfSegmentedControl.SelectionIndicatorSettings>
<sfCheckbox:SelectionIndicatorSettings x:Name="indicatorSettings"
Color="{Binding SegmentIndicatorColor}"
StrokeThickness="3"
CornerRadius="13"
Position="Fill">
</sfCheckbox:SelectionIndicatorSettings>
</sfCheckbox:SfSegmentedControl.SelectionIndicatorSettings>
</sfCheckbox:SfSegmentedControl>
In the ViewModel I have the following properties:
private Color _segmentControlColor;
public Color SegmentControlColor { get { return _segmentControlColor; } set { _segmentControlColor = value; OnPropertyChanged(); } }
private Color _segmentIndicatorColor;
public Color SegmentIndicatorColor { get { return _segmentIndicatorColor; } set { _segmentIndicatorColor = value; OnPropertyChanged(); } }
private async void ChecklistSelectionChanged(EventModels.SelectionChangedEventArgs eventArgs)
{
if (eventArgs.Index == 0)
{
SegmentControlColor = Color.FromHex("#BADAF6");
SegmentIndicatorColor = Color.FromHex("#007DEE");
}
else
{
SegmentControlColor = Color.FromHex("#E4E4E4");
SegmentIndicatorColor = Color.FromHex("#C2C1C1");
}
}
When I navigate to one of the pages, move the SegmentedControl indicator to the other selection(toggle the switch), then navigate away from that page to another and toggle that pages switch to the other selection, THEN move back to the original page and move the SegmentedControl indicator(toggle switch) again, I get a crash with the following stacktrace:
05-16 23:13:15.912 I/MonoDroid( 8488): UNHANDLED EXCEPTION:
05-16 23:13:15.916 I/MonoDroid( 8488): System.NullReferenceException: Object reference not set to an instance of an object.
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SfSegmentedControl.UpdateSelectionIndicator () [0x00006] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SfSegmentedControl.<set_SelectionIndicatorSettings>b__60_0 (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.RaiseOnPropertyChanged (System.String propertyName) [0x00012] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.set_Color (Android.Graphics.Color value) [0x00007] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.SetEquivalentValues (Syncfusion.XForms.Buttons.SelectionIndicatorSettings formSettings) [0x0000c] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.FormSettingsOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs propertyChangedEventArgs) [0x00000] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-16 23:13:15.916 I/MonoDroid( 8488): at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
05-16 23:13:15.916 I/MonoDroid( 8488): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:211
05-16 23:13:15.916 I/MonoDroid( 8488): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:339
05-16 23:13:15.916 I/MonoDroid( 8488): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:443
05-16 23:13:15.916 I/MonoDroid( 8488): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:379 Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
If I remove this binding, and say set it to a static color the issue goes away.
<sfCheckbox:SelectionIndicatorSettings
Color="{Binding SegmentIndicatorColor}"
---- Change To and problem goes away---
Color="Red"
So I know it's in issue with Binding to the Color property of the SelectionIndicatorSettings.
I know this is a complex scenario, and I can't share the complete solution, and I couldn't easily re-create it in a sample solution. I know it's a longshot, but hopefully you can look at the stacktrace and come up with a solution. I think I can work around it now by using an action from my viewmodel to access the view codebehind and change the color of the indicator directly, but don't want to keep that long term.
Any help will be greatly appreciated.
SIGN IN To post a reply.
5 Replies
MK
Muneesh Kumar G
Syncfusion Team
May 20, 2019 12:33 PM UTC
Hi John,
Greetings from Syncfusion.
We have prepared a sample to replicate the issue based on the provided code snippet, but we are afraid, that we are not able to reproduce the issue at our end. The sample we tried can be downloaded from the below location.
Since we are not aware of your exact application scenario, we were not able to reproduce this at our end, can you please revert us by modifying the sample based on your application along with replication procedure. This will be helpful for us to provide you better solution at the earliest.
Regards,
Muneesh Kumar G.
JP
John Prass
May 21, 2019 10:42 AM UTC
Thank you for looking into this. I'll update the sample to reflect what I'm seeing and return it to you soon.
MK
Muneesh Kumar G
Syncfusion Team
May 21, 2019 10:55 AM UTC
Hi John,
Thanks for your update and we will wait to hear from you.
Regards,
Muneesh Kumar G.
JP
John Prass
May 25, 2019 09:50 PM UTC
I've updated the sample to expose the issue. The updated solution is attached.
Attachment: SegmentedControlCrash_36456261.zip
Here is the sequence of events to recreate the issue:
1. Unzip the Solution
2. Load solution into vs 2019
3. Set GettingStartedButton.Android project as startup project.
4. Run (Debug) application in emulator.
5. Page 1 will load, toggle the segmented control.
6. Click the >> button to navigate to page 2.
7. Toggle the segmented control on page 2.
8. Click the << button to navigate back to page 1.
9. Toggle the segmented control on page 1 again.
10. An exception is thrown.
05-18 07:58:13.986 I/MonoDroid(12163): UNHANDLED EXCEPTION:
05-18 07:58:13.993 I/MonoDroid(12163): System.NullReferenceException: Object reference not set to an instance of an object.
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SfSegmentedControl.UpdateSelectionIndicator () [0x00006] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SfSegmentedControl.<set_SelectionIndicatorSettings>b__60_0 (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.RaiseOnPropertyChanged (System.String propertyName) [0x00012] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.set_Color (Android.Graphics.Color value) [0x00007] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.SetEquivalentValues (Syncfusion.XForms.Buttons.SelectionIndicatorSettings formSettings) [0x0000c] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Syncfusion.Android.Buttons.SelectionIndicatorSettings.FormSettingsOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs propertyChangedEventArgs) [0x00000] in <86670befeb3e494b8c5188a7f45de6ac>:0
05-18 07:58:13.994 I/MonoDroid(12163): at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:211
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:353
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:443
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:379
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00220] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:167
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:57
05-18 07:58:13.994 I/MonoDroid(12163): at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:618
05-18 07:58:13.994 I/MonoDroid(12163): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <788a34f7a7b84486905dfde786529d42>:0
05-18 07:58:13.994 I/MonoDroid(12163): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <788a34f7a7b84486905dfde786529d42>:0
05-18 07:58:13.994 I/MonoDroid(12163): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.18(intptr,intptr)
05-18 07:58:14.025 W/ngStartedButto(12163): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
05-18 07:58:14.037 D/Mono (12163): DllImport searching in: '__Internal' ('(null)').
05-18 07:58:14.037 D/Mono (12163): Searching for 'java_interop_jnienv_throw'.
05-18 07:58:14.037 D/Mono (12163): Probing 'java_interop_jnienv_throw'.
05-18 07:58:14.037 D/Mono (12163): Found as 'java_interop_jnienv_throw'.
I hope this helps you find the issue.
Thank you.
Attachment: SegmentedControlCrash_36456261.zip
MK
Muneesh Kumar G
Syncfusion Team
May 27, 2019 12:42 PM UTC
Hi John,
Thanks for your update.
We have fixed the reported issue “Null reference exception with Segment control” in Android. Please download the patch in below
Please find the patch setup from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.47/706508/F144720/SyncfusionPatch_17.1.0.47_706508_5272019073318664_F144720.exe
http://syncfusion.com/Installs/support/patch/17.1.0.47/706508/F144720/SyncfusionPatch_17.1.0.47_706508_5272019073318664_F144720.exe
(OR)
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.47/706508/F144720/SyncfusionPatch_17.1.0.47_706508_5272019073318664_F144720.zip
(OR)
Please find the NuGet from below location:
http://syncfusion.com/Installs/support/patch/17.1.0.47/706508/F144720/SyncfusionNuget_17.1.0.47_706508_5272019073318664_F144720.zip
Assembly Version: 17.1.0.47
Disclaimer:
Please note that we have created this patch for version 17.1.0.47 specifically to resolve the following issue reported in this incident. If you have received other patches for the same version for other products, please apply all patches in the order received.
This fix will be included in our upcoming weekly nuget release.
Regards,
Regards,
Muneesh Kumar G.
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
JP John Prass
- May 19, 2019 05:14 PM UTC
- May 27, 2019 12:42 PM UTC