【问题标题】:Xamarin.Forms.Skeleton - What make animation and BackgroundColor of the plugin doesn't appears?Xamarin.Forms.Skeleton - 是什么让插件的动画和 BackgroundColor 不出现?
【发布时间】:2020-04-06 12:00:27
【问题描述】:

我已经在我的 xamarin.form 应用程序中实现了 Skeleton 插件。它在我的列表视图页面中运行良好。然后我在我的 listView 项目详细信息中尝试它,动画和骨架背景颜色不起作用。该功能工作正常,在我的构建中没有错误。

这是我尝试过的:

my xaml layout:

<ScrollView BackgroundColor="White">
        <StackLayout
               Margin="15"
               extension:Skeleton.IsParent="True"
               extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
               extension:Skeleton.BackgroundColor="{StaticResource GrayColor}"
               extension:Skeleton.Animation="Fade"
               extension:Skeleton.AnimationInterval="600">
            <Image
                   x:Name="ImgSelfie"
                   HeightRequest="200" WidthRequest="200" BackgroundColor="White"
                   Source="selfie"
                   extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
                   extension:Skeleton.Animation="Fade"
                   extension:Skeleton.BackgroundColor="{StaticResource DarkGrayColor}"/>
            <Label Text="Location :" FontAttributes="Bold"/>
            <Editor
                   Text="{Binding Attend.AddressDetail}" x:Name="EdtLocation" IsEnabled="False" AutoSize="TextChanges"
                   extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
                   extension:Skeleton.Animation="Fade"
                   extension:Skeleton.BackgroundColor="{StaticResource DarkGrayColor}"/>

            <Label Text="Time :" FontAttributes="Bold"/>
            <Entry
                   Text="{Binding Attend.Created}" x:Name="EntTime" IsEnabled="False"
                   extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
                   extension:Skeleton.Animation="Fade"
                   extension:Skeleton.BackgroundColor="{StaticResource DarkGrayColor}" />

            <Label Text="Action :" FontAttributes="Bold"/>
            <Label
                   Text="{Binding Attend.Activity}" x:Name="LblAction" FontSize="Medium" TextColor="Black"
                   extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
                   extension:Skeleton.Animation="Fade"
                   extension:Skeleton.BackgroundColor="{StaticResource DarkGrayColor}"/>

            <Label Text="Noted :" FontAttributes="Bold"/>
            <Editor
                   Text="{Binding Attend.Note}" x:Name="EntNote" IsEnabled="False" AutoSize="TextChanges"
                   extension:Skeleton.IsBusy="{Binding IsLoadBusy}"
                   extension:Skeleton.Animation="Fade"
                   extension:Skeleton.BackgroundColor="{StaticResource DarkGrayColor}"/>

            <StackLayout VerticalOptions="EndAndExpand">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <material:MaterialButton
                   mvx:Bi.nd="Command OnCancelButtonCommand" Text="Confirm"
                   ButtonType="Outlined" BorderColor="Black" BackgroundColor="White"
                   TextColor="Black" PressedBackgroundColor="Gray" BorderWidth="2" WidthRequest="25" Padding="15"/>
                </Grid>
            </StackLayout>
        </StackLayout>
    </ScrollView>

和the view model:

    public async Task PerformShimmerAsyncTask(string id)
    {
        this.Attend = new Attendance
        {
            //Image = null,
            AddressDetail = "x",
            Created = DateTime.Now,
            Activity = "x",
            Note = "x"
        };

        this.IsLoadBusy = true;
        await Task.Delay(2500);
        this.IsLoadBusy = false;
        //await GetItem(id);

        this.Attend = new Attendance
        {
           //Image = "selfie.png",
           AddressDetail = "asdasdasda",
           Created = DateTime.Now,
           Activity = "sadasdasdasfacf",
           Note = "asuuusfasfa"
        };
    }

以下基于此example.

如果我的问题还不清楚,请帮助和纠正。

【问题讨论】:

  • 你试过 Syncfusion Shimmer 吗?
  • 还没有,因为我认为我们必须付费才能使用它。我说的对吗?

标签: c# xamarin xamarin.forms mvvmcross shimmer


【解决方案1】:

我使用你的代码,它在我这边运行良好,我可以向你展示我的示例项目。

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();


        myViewModel vm = new myViewModel();

        this.BindingContext = vm;
        vm.PerformShimmerAsyncTask("123");
    }
}

public class myViewModel : BaseViewModel
{

    private MyModel _attend;
    private bool _isLoadBusy = false;

    public MyModel Attend
    {
        get { return _attend; }
        set { SetProperty(ref _attend, value); }
    }

    public bool IsLoadBusy
    {
        get { return _isLoadBusy; }
        set
        {
            _isLoadBusy = value;
            OnPropertyChanged();
        }
    }

    public async Task PerformShimmerAsyncTask(string id)
    {

        this.Attend = new MyModel
        {
            AddressDetail = "x",
            Created = DateTime.Now,
            Activity = "x",
            Note = "x"
        };

        this.IsLoadBusy = true;
        await Task.Delay(10000);
        this.IsLoadBusy = false;

        this.Attend = new MyModel
        {
            AddressDetail = "asdasdasda",
            Created = DateTime.Now,
            Activity = "sadasdasdasfacf",
            Note = "asuuusfasfa"
        };
    }

}

public class MyModel 
{
    public string AddressDetail { get; set; }
    public DateTime Created { get; set; }
    public string Activity { get; set; }
    public string Note { get; set; }
}

Xaml 中的代码与您的相同。你应该确保你设置了正确的bindingContext并正确调用PerformShimmerAsyncTask。

我上传了我的示例项目here。让我知道它是否适合你。

【讨论】:

  • 对不起,如果这有点离题,我在我的 android 设备 API 级别 28(Pie) 中运行您的项目,然后我收到警告“无法获得 aapt2 版本。禁用 aapt2支持。请检查它是否安装正确”我已经安装了 Android SDK 构建工具 26.0.0 - 26.0.3 但仍然相同。
  • 那么SetProperty方法的作用是什么?它使值不能出现。这是我的项目唯一不同的地方。
  • @Machtal 请检查解决方案here。
  • @Machtal 来自BaseViewModel
  • @Machtal 所以我的样本适合你,对吧?我猜当您更改 Attend 的值时不会触发 OnPropertyChanged。
猜你喜欢
  • 1970-01-01
  • 2015-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-21
  • 1970-01-01
  • 2021-04-11
相关资源
最近更新 更多