UXDivers / Grial-UI-Kit-Support

This is our public repository for customers to report bugs about Grial UI Kit for Xamarin Forms
61 stars 26 forks source link

TabControl throwing argumentNull Exception and not working in collectionView #857

Open tentom opened 11 months ago

tentom commented 11 months ago

When using a TabControl within a CollectionView ItemTemplate the TabControl throws an exception in the "ForceSelection" function. This was working in a previous version of GrialKit package.

Description

Adding SelectedItem="tab 1" to the tabControl stops the exception from being thrown, but the control is still not working as expected.

Adding the Control directly to the Content of the content page the TabControll is shown correctly but this is not the desired behaviour for my use case.

Steps to Reproduce

  1. Add this content as the content of a ContentPage

    <ContentPage.Content>
    <CollectionView
            ItemsSource="{Binding Groups3}"
            >
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <grial:TabControl
                        BackgroundColor="Teal"
                        TabStripHeight="30"
                        HeightRequest="150"
                        WidthRequest="150"
    
                        >
                        <grial:TabItem Text="tab 1">
                            <Grid BackgroundColor="Gray">
                            </Grid>
                        </grial:TabItem>
                        <grial:TabItem Text="tab 2">
                            <Grid BackgroundColor="Green">
                            </Grid>
                        </grial:TabItem>
                        <grial:TabItem Text="tab 3">
                            <Grid BackgroundColor="Yellow">
                            </Grid>
                        </grial:TabItem>
                   </grial:TabControl>
                </DataTemplate>
            </CollectionView.ItemTemplate>
    
        </CollectionView>
    </ContentPage.Content>
  2. And this to the binding context
    public ObservableCollection<string> Groups3 { get; } = new ObservableCollection<string>() {
            { "Test1" },
            { "Test2" },
        };
  3. Compile and navigate to the page to see the exception
  4. Add the following to the Grial:TabControl and the error goes away
    SelectedItem="tab 1" 

Expected Behavior

Actual Behavior

This error appears without the SelectedItem="tab 1"

*** Terminating app due to uncaught exception 'System.ArgumentNullException', reason: 'Value cannot be null. (Parameter 'key') (System.ArgumentNullException)
   at System.Collections.Generic.Dictionary`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].FindValue(Object key)
   at System.Collections.Generic.Dictionary`2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].get_Item(Object key)
   at UXDivers.Grial.TabControl.ForceSelection(Object oldItem, Object selectedItem)
   at UXDivers.Grial.TabControl.OnSelectedItemChanged(BindableObject bindable, Object oldValue, Object newValue)
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
   at UXDivers.Grial.TabControl.set_SelectedItem(Object value)
   at UXDivers.Grial.TabControl.<>c__DisplayClass125_0.<OnHandlerChanged>b__0()
   at Microsoft.Maui.Dispatching.Dispatcher.<>c__DisplayClass9_0.<DispatchImplementation>b__0()
   at CoreFoundation.DispatchQueue.static_dispatcher_to_managed(IntPtr context) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/CoreFoundation/Dispatch.cs:line 379
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at Program.Main(String[] args) in mauiTestproject/Platforms/iOS/Program.cs:line 13

With the added SelectedItem="tab 1" the view loads but the tabControl is non functional.

Basic Information