diff --git a/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.Android.cs b/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.Android.cs index d67e756ed..0970fa1b4 100644 --- a/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.Android.cs +++ b/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.Android.cs @@ -135,45 +135,45 @@ protected override void Render() if (_isInOverflow) { - native.SetTitle(null); native.SetActionView(null); - native.SetIcon(null); + native.SetTitle(null); } else { - var iconOrContent = element.Icon ?? element.Content; - switch (iconOrContent) + var iconOrContent = element.Icon ?? element.Content ?? element.Label; + + if (iconOrContent is string || (iconOrContent is FrameworkElement fe && fe.Visibility == Visibility.Visible)) { - case string text: - native.SetIcon(null); - native.SetActionView(null); - native.SetTitle(text); - break; - - case FrameworkElement fe: - if (fe.Visibility == Visibility.Visible && _appBarButtonWrapper is { } wrapper) - { - wrapper.Child = element; + if (_appBarButtonWrapper is { } wrapper) + { + wrapper.Child = element; - //Restore the original parent if any, as we - // want the DataContext to flow properly from the - // CommandBar. - element.SetParent(_elementParent); + // Restore the original parent if any, as we + // want the DataContext to flow properly from the + // CommandBar. + element.SetParent(_elementParent); - native.SetIcon(null); - native.SetActionView(wrapper); + if (iconOrContent is string text) + { + wrapper.Child = (UIElement)native.SetTitle(text); + } + else + { native.SetTitle(null); } - break; - default: - native.SetIcon(null); - native.SetActionView(null); - native.SetTitle(null); - break; + native.SetActionView(wrapper); + } + } + else + { + native.SetActionView(null); + native.SetTitle(null); } } + native.SetIcon(null); + // IsEnabled native.SetEnabled(element.IsEnabled); // According to the Material Design guidelines, the opacity inactive icons should be: diff --git a/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.iOS.cs b/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.iOS.cs index 471a5a7c6..f0b307058 100644 --- a/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.iOS.cs +++ b/src/Uno.Toolkit.UI/Controls/NavigationBar/AppBarButtonRenderer.iOS.cs @@ -117,16 +117,12 @@ protected override void Render() var native = Native; var element = Element ?? throw new InvalidOperationException("Element is null."); - var iconOrContent = element.Icon ?? element.Content; - switch (iconOrContent) - { - case string text: - native.Image = null; - native.ClearCustomView(); - native.Title = text; - break; + var iconOrContent = element.Icon ?? element.Content ?? element.Label; - case FrameworkElement fe: + if (iconOrContent is string || (iconOrContent is FrameworkElement fe && fe.Visibility == Visibility.Visible)) + { + if (_appBarButtonWrapper is { } wrapper) + { var currentParent = element.Parent; _appBarButtonWrapper.Child = element; @@ -136,19 +132,19 @@ protected override void Render() element.SetParent(currentParent); native.Image = null; - native.CustomView = fe.Visibility == Visibility.Visible ? _appBarButtonWrapper : null; + native.CustomView = _appBarButtonWrapper; // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. // We default to an empty string to ensure it is added, in order to support late-bound Content. - native.Title = string.Empty; - break; - - default: - native.Image = null; - native.ClearCustomView(); - // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. - // We default to an empty string to ensure it is added. - native.Title = string.Empty; - break; + native.Title = iconOrContent is string text ? text : string.Empty; + } + } + else + { + native.Image = null; + native.ClearCustomView(); + // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. + // We default to an empty string to ensure it is added. + native.Title = string.Empty; } // Label