我对毛伊岛和这类动画还是个新手.我有一个定制的筛选器控件,它可以判断输入的数据是否与存储在字典中的数据匹配.如果匹配,集合视图的项源将填充这些数据(保存在可观察的集合中).如果没有匹配,则集合视图将为空,因此我将集合视图的emptyview属性定义为:

<CollectionView.EmptyView>
   <ContentView MinimumHeightRequest="485" IsVisible="{Binding IsEmpty}">
      <VerticalStackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand"
                           Spacing="30"
                           Margin="0, 0, 0, 0">
         <Grid HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand">
            <lottie:SKLottieView Source="earthanimation.json"
                                 RepeatCount="-1"
                                 HeightRequest="350"
                                 WidthRequest="350"
                                 HorizontalOptions="CenterAndExpand"
                                 VerticalOptions="CenterAndExpand"/>
            <Label Text="NOT FOUND" TextColor="LightBlue"
                   FontFamily="FAR" FontSize="30" FontAttributes="Bold"
                   VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
         </Grid>

         <Label Text="Location not found"
                FontSize="15" FontFamily="Conthrax"
                HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
      </VerticalStackLayout>
   </ContentView>
</CollectionView.EmptyView>

注意,我绑定了IsVisible属性,这是因为当点击筛选器条目时,即使我没有搜索到任何内容,也会触发一些内容并显示Emptyview.因此,我将其设置为只有在实际搜索过程返回0个匹配项时才可见. 这只是为了澄清对这一点的任何怀疑.

一切都运行得很好,除了Lottie动画,它没有显示任何东西,这是使其工作的唯一方法,在调试中,当应用程序运行时,我删除了Lottie控件,然后一旦用户界面刷新,我将它粘贴回go ,它就工作了……

我不知道该如何解决这件事.

我试着在互联网上查找,但这种信息真的很具体,真的很难找到.所以遗憾的是,我没有找到解决方案.

推荐答案

是的,我可以复制这个.我发现的解决办法不是很优雅,但对我来说很管用.这就是删除Lottie并在后面的代码中重新添加它.请try 以下代码:

100.Please note that we should also add the lottie in the xaml,否则不会显示.

<Button
   x:Name="CounterBtn"
   Text="Click me"
   SemanticProperties.Hint="Counts the number of times you click"
   Command="{Binding ClickedCommand}"
   HorizontalOptions="Center" />

....

<CollectionView.EmptyView>
   <ContentView MinimumHeightRequest="485" IsVisible="{Binding IsEmpty}">
      <VerticalStackLayout x:Name="mystack" HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand"
                           Spacing="30"
                           Margin="0, 0, 0, 0">
         <Grid x:Name="mygrid" HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand" HeightRequest="350"
                                 WidthRequest="350">

           <skia:SKLottieView  x:Name="mylot" Source="dotnetbot.json"
                                   RepeatCount="-1"
                                   HeightRequest="350"
                                   WidthRequest="350"
                                   HorizontalOptions="CenterAndExpand"
                                   VerticalOptions="CenterAndExpand"/>
           <Label Text="NOT FOUND" TextColor="Black"
               FontFamily="FAR" FontSize="30" FontAttributes="Bold"
               VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>

         </Grid>

         <Label Text="{Binding MyText}"
                FontSize="15" FontFamily="Conthrax"
                HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
      </VerticalStackLayout>
   </ContentView>

在视图模型中,让我们实现ClickedCommand.请注意,我这里使用的是MessagingCenter.因为当集合中没有任何项时,我们希望向后端代码发送一条消息以再次添加Lottie

    public Command ClickedCommand
    {
        get
        {
            return new Command(() =>
            {
                ItemCollection.RemoveAt(0);
                if(ItemCollection.Count ==0)
                {
                    MessagingCenter.Send<MainPageViewModel>(this, "Hi");
                }

            });

        }
    }

在.NET 7中,建议使用WeakReferenceMessenger而不是MessagingCenter.这些用法是相似的.

100,我们只需订阅消息,然后删除并再次添加Lottie.

public MainPage()
{
    InitializeComponent();
    this.BindingContext = viewModel = new MainPageViewModel();
    MessagingCenter.Subscribe<MainPageViewModel>(this, "Hi", (s) =>
    {
        mygrid.Clear();
        SKLottieView myanimatedview = new SKLottieView();
        var a = new SKFileLottieImageSource();
        a.File = "dotnetbot.json";
        myanimatedview.WidthRequest = 300;
        myanimatedview.HeightRequest = 300;
        myanimatedview.Source = a;
        myanimatedview.RepeatCount = -1;
        mygrid.Add(myanimatedview);
        Label label = new Label()
        {
            Text = "NOT FOUND",
            TextColor = Colors.LightBlue,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };
        mygrid.Add(label);
    });


}

有关更多信息,您可以参考SKLottieView.您也可以在Github:SKLottie Issues on Github上报告问题

希望它能帮上忙!

enter image description here

Csharp相关问答推荐

VB.Net的SON模式导致集合代码不工作

为什么我在PuppeteerSharp中运行StealthPlugin时会出现错误?

EF Core:看不到任何查询日志(log)?

O(N)测试失败

获取ASP.NET核心身份认证cookie名称

如何保持主摄像头视角保持一致?

LINQ无法翻译SQLFunctions方法

TDLib与机器人共享电话号码

. NET 8控制台应用程序DI错误无法解析Microsoft. Extension. Logging. ILoggerFactory类型的服务'''

WPF DataGrid中的三维数据

XUNIT是否使用测试数据的源生成器?

在.NET核心项目中创建Startup.cs比在Program.cs中注册服务好吗?

同一组件的多个实例触发相同的事件处理程序

如何使用.NET Aspire从Blazor应用程序与GRPC API通信?

如何将默认区域性更改为fr-FR而不是en-US?

如何在C#.NET桌面应用程序中动态更改焦点工具上的后退 colored颜色

如何读取TagHelper属性的文本值?

项目参考和方法签名问题

HttpClient,上传文件时实现进度

我想我必须手动使用res1(字符串形式的PowerShell哈希表)