简体   繁体   English

有没有办法在 MAUI.NET 中显示从 View.xaml.cs 到 View.xaml 的文本?

[英]Is there a way to display text that I get from my View.xaml.cs to my View.xaml in MAUI.NET?

I am trying to figure out how to display text of totalClients that I get from my View.xaml.cs on my View.xaml.我试图弄清楚如何在 View.xaml 上显示从 View.xaml.cs 获得的 totalClients 的文本。

View.xaml查看.xaml

<VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center">

                <Label Text="{Binding TotalClients}" TextColor="{x:StaticResource BankrWhite}" FontSize="100" FontFamily="SFProDisplayMedium" HorizontalTextAlignment="Center" CharacterSpacing="12.8"/>
                <Label TextColor="{x:StaticResource BankrYellow}" Text="total clients" FontSize="24" FontFamily="SFProDisplaySemibold" TextTransform="Uppercase" HorizontalTextAlignment="Center" CharacterSpacing="4.32"/>          

</VerticalStackLayout>

View.xaml.cs查看.xaml.cs

protected override async void OnAppearing()
    {
        base.OnAppearing();
        int clients = App.ClientRepo.GetClientsTotal();

        TotalClients.Text = clients.ToString();
    }

yes, you can assign values directly to an element by assigning it an x:Name是的,您可以通过为其分配x:Name来直接为元素分配值

<Label x:Name="lblTotalClients" ...

then in the code behing然后在代码中

lblTotalClients.Text = clients.ToString();

however, data binding is generally the prefered approach但是, 数据绑定通常是首选方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM