簡體   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?

我試圖弄清楚如何在 View.xaml 上顯示從 View.xaml.cs 獲得的 totalClients 的文本。

查看.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>

查看.xaml.cs

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

        TotalClients.Text = clients.ToString();
    }

是的,您可以通過為其分配x:Name來直接為元素分配值

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

然后在代碼中

lblTotalClients.Text = clients.ToString();

但是, 數據綁定通常是首選方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM