Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Is there a way via XAML to add a ToolbarItem conditionally, for only specified TargetPlatforms?

$
0
0

For Views, I found a good XAML workaround to conditional display per platform, by setting View.IsVisible using OnPlatform, like so:

<Button Text="Whatever">
  <Button.IsVisible>
    <OnPlatform x:TypeArguments="x:Boolean">
      <OnPlatform.iOS>True</OnPlatform.iOS>
      <OnPlatform.Android>False</OnPlatform.Android>
      <OnPlatform.WinPhone>False</OnPlatform.WinPhone>
    </OnPlatform>
  </Button.IsVisible>
</Button>

But for a ToolbarItem, which isn't a View and doesn't have IsVisible, I can't use that approach. I'm trying to use OnPlatform in the only way I can think to do it (below), but this gives me a System.Reflection.TargetInvocationException.

<ContentPage.ToolbarItems>
  <OnPlatform x:TypeArguments="ToolbarItem">
    <OnPlatform.iOS>
      <ToolbarItem Name="Whatever" />
    </OnPlatform.iOS>
  </OnPlatform>
</ContentPage.ToolbarItems>

Is what I want to do possible? And to make clear up front, I know this can be done in the codebehind, but I want to know if there's a XAML solution. If so, could someone please point me in the right direction? Thanks!


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>