How to define boolean key in app.xaml?

Charlie2017Charlie2017 USMember ✭✭
edited January 2017 in Xamarin.Forms

How to define a global resource dictionary boolean key, ShowMyMenu, and use it to show or hide myMenu

<local:myMenu x:Name="myMenu" HorizontalOptions="FillAndExpand" VerticalOptions="Start" IsVisible="{StaticResource ShowMyMenu}" />

I tried same different ways in App.xaml file, but they can't be executed:

<x:bool x:key="ShowMyMenu">True</x:bool>

<x:Boolean x:key="ShowMyMenu">True</x:Boolean>

<Boolean x:key="ShowMyMenu">True</Boolean>

Thanks for your help

Posts

  • ionixjuniorionixjunior USMember ✭✭✭

    Hi @Charlie2017, if you want only add on your visibility property True or False values, is not more easy only add True or False directly inside XAML?

    If you visibility is dynamic, I suggest you define a binding instead static resource.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @ionixjunior @Charlie2017

    I agree it seems a little odd the way you're going about what looks like a settings or permissions system.
    But it can sometimes be easier to have a StaticReference for some things like this, especially if you are working out some kind of multi-binding system where you need a XAML trigger or parameter to send to a converter for comparison.

    But to answer the question of what the syntax is; here ya go. I used keys that made it easy in my xaml

                <x:Boolean x:Key="True">True</x:Boolean>
                <x:Boolean x:Key="False">False</x:Boolean>
    

    I think the mistake you made was in caseing. Key is with an upper case K

  • voidstreamvoidstream FRMember ✭✭✭

    @ClintStLaurent said:
    @ionixjunior @Charlie2017

    I agree it seems a little odd the way you're going about what looks like a settings or permissions system.
    But it can sometimes be easier to have a StaticReference for some things like this, especially if you are working out some kind of multi-binding system where you need a XAML trigger or parameter to send to a converter for comparison.

    But to answer the question of what the syntax is; here ya go. I used keys that made it easy in my xaml

                <x:Boolean x:Key="True">True</x:Boolean>
                <x:Boolean x:Key="False">False</x:Boolean>
    

    I think the mistake you made was in caseing. Key is with an upper case K

    Uppercase error yeah ;)

Sign In or Register to comment.