I created a ToolbaItems in a ContentPage that is a ShellContent from FlyoutItem - I am using ShellApp.
<ContentPage.ToolbarItems>
<ToolbarItem
x:Name="xicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.x.png}"
Text="Saw X" />
<ToolbarItem
x:Name="yicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.y.png}"
Text="Saw Y" />
<ToolbarItem
x:Name="zicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.z.png}"
Text="Saw Z" />
</ContentPage.ToolbarItems>
In Android it works well, but in iOS I got an error:
Message "Cannot access a disposed object.\n
Object name: 'PrimaryToolbarItem'." string
$exception {System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'PrimaryToolbarItem'.
at Foundation.NSObject.get_SuperHandle () [0x00012] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:469
at UIKit.UIBarButtonItem.set_Image (UIKit.UIImage value) [0x0002b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIBarButtonItem.g.cs:827
at Xamarin.Forms.Platform.iOS.ToolbarItemExtensions+PrimaryToolbarItem.UpdateIconAndStyle () [0x00031] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Extensions\ToolbarItemExtensions.cs:84
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at Toretto.MobileApp.iOS.Application.Main (System.String[] args) [0x00001] in C:\Projects\Toretto\Toretto.MobileApp\src\Toretto.MobileApp\Toretto.MobileApp.iOS\Main.cs:17 } System.ObjectDisposedException
If I remove theses items in the constructor of the ContentPage it does not crash, I tried to use only Text, in Android I am using icon and works...
public HomePage()
{
InitializeComponent();
if (DeviceInfo.Platform == DevicePlatform.iOS)
{
this.ToolbarItems.Clear();
}
}
Is this a bug? In github I saw few issue about toolbar.
OnAppearing