【问题标题】:Xamarin Community Toolkit StateLayout not showingXamarin 社区工具包 StateLayout 未显示
【发布时间】:2021-10-08 23:54:52
【问题描述】:

我正在尝试为 Xamarin 表单页面实现 StateLayout,如下所述: https://docs.microsoft.com/en-us/xamarin/community-toolkit/views/statelayout

但是,我无法显示加载状态视图。

重现步骤:

  1. 创建一个 Xamarin Forms 空白应用。
  2. 添加 Xamarin 社区工具包参考。
  3. 使用此代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="App4.MainPage">

    <Grid xct:StateLayout.CurrentState="Loading">
        <xct:StateLayout.StateViews>
            <xct:StateView StateKey="Loading">
                <Grid BackgroundColor="White">
                    <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                        <ActivityIndicator Color="#1abc9c" />
                        <Label TextColor="Red" FontSize="50" Text="Loading..." HorizontalOptions="Center" />
                    </StackLayout>
                </Grid>
            </xct:StateView>
        </xct:StateLayout.StateViews>

        <Label Text="Loaded" />

    </Grid>

</ContentPage>

我得到的不是“正在加载”标签是这样的:

我做错了什么?

【问题讨论】:

    标签: xamarin


    【解决方案1】:

    根据你显示的文档,你应该在StateLayout.CurrentState属性上使用Binding,然后在对应的cs页面上创建一个LayoutState类型的变量,并使用CurrentState = LayoutState.Loading;赋值才能正常显示。

    【讨论】:

    • 你是对的。通过使用绑定,我可以显示加载状态。我不明白为什么我不能在没有任何绑定的情况下设置 xct:StateLayout.CurrentState="Loading" 。还是谢谢。
    猜你喜欢
    • 2023-03-11
    • 2021-10-12
    • 2021-09-21
    • 2021-05-06
    • 2019-11-09
    • 2021-08-04
    • 1970-01-01
    • 2021-07-25
    • 2022-01-21
    相关资源
    最近更新 更多