How do i call/display Application.Current.properties[''Name''].Tostring() in Xaml page?

And I am new to xamarin. Kindly help me on this.
Loginusername is label type.

Best Answer

  • RamprasadKRamprasadK US ✭✭
    edited July 2017 Accepted Answer

    Got it . Thanks for the replies @AlessandroCaliaro

    **My Xaml : **
    <Label x:Name="LoginUserName"></Label>

    CODE

    LoginUserName.Text = App.Current.Properties["LoginUserName"].ToString();

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think "usernme" should be a property. in its "get" use "return App.current....." and bind "usernme" to a control in your XAML

  • RamprasadKRamprasadK USMember ✭✭
    edited July 2017

    Hi @AlessandroCaliaro,

    Thanks for the reply.
    private string user = "Some text";
    public string Username { get { return user; } set { user = value; } }
    How would i call/display/bind this in Xaml page?
    Kindly Send me the code.
    Thanks in advance.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    string username {get{return App.Current.Properties["LoginUserName"].ToString();}; set;}
    

    and Bind this to a control

  • RamprasadKRamprasadK USMember ✭✭

    Hi @AlessandroCaliaro,

    I don't know the syntax for binding this property in xaml.

  • RamprasadKRamprasadK USMember ✭✭
    edited July 2017 Accepted Answer

    Got it . Thanks for the replies @AlessandroCaliaro

    **My Xaml : **
    <Label x:Name="LoginUserName"></Label>

    CODE

    LoginUserName.Text = App.Current.Properties["LoginUserName"].ToString();

  • JontyJonty Member ✭✭

    This is what worked for me:

    C#

    public static string HeaderFontSize { get { return Current.Properties["HeaderFontSize"].ToString(); } }
    
    public App()
    {
        Current.Properties["HeaderFontSize"] = "Medium";
    }
    

    XAML - App.xaml

    <Application xmlns:local="clr-namespace:LibraryApp">
    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="Label" x:Key="HeaderFont">
                <Setter Property="FontSize" Value="{x:Static local:App.HeaderFontSize}"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
    

    XAML - ViewPage.xaml

    <Label Margin="5" Text="MyLabel" Style="{StaticResource HeaderFont}" />

Sign In or Register to comment.