on MAUI,CollectionView using itemtemplate in which a SwipeView,when the binding data refreshes,i scroll at the same time,it died.

尼龟 杰 190 Reputation points
2023-04-16T06:59:58.6666667+00:00
<DataTemplate x:Key="searchlistAn">
            <SwipeView Padding="0,0,10,0">
                <SwipeView.RightItems>
                    <SwipeItem Text="2333" BackgroundColor="Red"></SwipeItem>
                </SwipeView.RightItems>
                <SwipeView.Content>
                    <Frame Padding="10">
                        <Frame.GestureRecognizers>
                            <TapGestureRecognizer Tapped="ClickGestureRecognizer_Clicked"/>
                        </Frame.GestureRecognizers>
                        <Grid Padding="0" ColumnDefinitions="auto,auto,2*,*,*" ColumnSpacing="10">
                            <Border Grid.Column="0" BackgroundColor="#0066FF" HeightRequest="5" WidthRequest="5" StrokeThickness="0">
                                <Border.StrokeShape>
                                    <RoundRectangle CornerRadius="5"></RoundRectangle>
                                </Border.StrokeShape>
                            </Border>
                            <Border Padding="0" HeightRequest="50" WidthRequest="50" Grid.Column="1" StrokeThickness="0">
                                <Border.StrokeShape>
                                    <RoundRectangle CornerRadius="10"/>
                                </Border.StrokeShape>
                                <Grid WidthRequest="50" HeightRequest="50">
                                    <Image Aspect="Fill" Source="defimage.webp" WidthRequest="50" HeightRequest="50"></Image>
                                    <Image Aspect="Fill" WidthRequest="50" HeightRequest="50">
                                        <Image.Source>
                                            <UriImageSource Uri="{Binding ImageUrl}" CacheValidity="5"/>
                                        </Image.Source>
                                    </Image>
                                </Grid>
                            </Border>
                            <Label VerticalOptions="Center" Text="{Binding songname}" Grid.Column="2"></Label>
                            <Label VerticalOptions="Center" Text="{Binding singer}" Grid.Column="3"></Label>
                            <Label VerticalOptions="Center" Text="{Binding abname}" Grid.Column="4"></Label>
                        </Grid>
                    </Frame>
                </SwipeView.Content>
            </SwipeView>
        </DataTemplate>
<CollectionView x:Name="mycoll" Grid.Row="3" Grid.Column="0" ItemsSource="{DynamicResource mkarr}" ItemTemplate="{StaticResource searchlistAn}" SelectionMode="None" Scrolled="mycoll_Scrolled">

Resources["mkarr"] = await QQmusic.search(searchBar.Text.Replace(" ", ""));

public static async Task<List<songbase>> search(string keyword)
        {
             return new List<songbase>();
        }

public class songbase
{
    public string songname { get; set; }
    public string singer { get; set; }
    public string abname { get; set; }
    public string ImageUrl { get; set; }
    public string mid { get; set; }
    public string id { get; set; }
}

这个list的数据: songbase,songbase.songname,songbase.singer,songbase.abname,songbase.ImageUrl,songbase.mid,songbase.id jngMUSIC_MAUITEST.songbase,坏女孩,徐良/小凌,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000002apRhZ4Bq99d.jpg,0001oIjs0YFIf7,"" jngMUSIC_MAUITEST.songbase,犯贱,徐良/阿悄,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000003e3ohO0HKzIL.jpg,001QOU9Y4T1cmZ,"" jngMUSIC_MAUITEST.songbase,客官不可以,徐良/小凌,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000003e3ohO0HKzIL.jpg,004WtRjE21f2dN,"" jngMUSIC_MAUITEST.songbase,七秒钟的记忆,徐良/孙羽幽,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M0000029sRLP45DyKu.jpg,003o0Acd4PWz2j,"" jngMUSIC_MAUITEST.songbase,后会无期,汪苏泷/徐良,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000002apRhZ4Bq99d.jpg,004gZy7l1GYJ1Q,"" jngMUSIC_MAUITEST.songbase,红装,徐良/阿悄,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000003e3ohO0HKzIL.jpg,000fHxUW1i2uG8,"" jngMUSIC_MAUITEST.songbase,那时雨,徐良,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000002JsVIJ31j7qR.jpg,0013aGOv4ZNeXI,"" jngMUSIC_MAUITEST.songbase,他的猫,徐良/杨曦,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M0000029sRLP45DyKu.jpg,002O44py1SBulq,"" jngMUSIC_MAUITEST.songbase,飞机场,徐良/小凌,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000000wcMxg3sNfzp.jpg,000zndnl2NpgQk,"" jngMUSIC_MAUITEST.songbase,和平分手,徐良/Britneylee小暖,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000003e3ohO0HKzIL.jpg,00308aAJ45za7I,"" jngMUSIC_MAUITEST.songbase,情话,徐良/孙羽幽,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M0000029sRLP45DyKu.jpg,004Vp4x21F5jX3,"" jngMUSIC_MAUITEST.songbase,电话里的秘密,徐良,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000002apRhZ4Bq99d.jpg,003YY2C00B7ajE,"" jngMUSIC_MAUITEST.songbase,无颜女,徐良/小凌,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M0000045N6AZ0WhO0s.jpg,002A39va2jsOXd,"" jngMUSIC_MAUITEST.songbase,后会无期,徐良/汪苏泷,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000002z54BF0JsMyR.jpg,003HLZCt3McOHO,"" jngMUSIC_MAUITEST.songbase,抽离,徐良/刘丹萌,QQ音乐,https://y.gtimg.cn/music/photo_new/T002R300x300M000001GraMO3JQQLr.jpg,0018BYrF3ANbLX,"" 调试跳转: QQ截图20230416150153

非常感谢您的任何回答。

Developer technologies .NET .NET MAUI
Developer technologies .NET Other
Developer technologies C#
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2023-04-16T13:53:59.2466667+00:00

    Hello,

    As you 尼龟 杰 said, it woks when you remove the SwipeView in the ItemTemplate.

    when i produce a different platform,i wouldn't like to recode ,how can i do?

    You can customize UI appearance based on the platform and device idiom, and refer to the following code:

    Define different template

    <ContentPage.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="SwipeTemplate">
                    <SwipeView>
                       ......
                </SwipeView>
                </DataTemplate>
            </ResourceDictionary>
           <ResourceDictionary>
                <DataTemplate x:Key="WithoutSwipeTemplate">
                    ......
                </DataTemplate>
            </ResourceDictionary>
       </ContentPage.Resources>
    

    Set different template to the CollectionView

     <CollectionView >
            <CollectionView.ItemTemplate>
                <OnPlatform x:TypeArguments="DataTemplate">
                    <On Platform="iOS, Android" Value="{StaticResource SwipeTemplate}" />
                    <On Platform="WinUI" Value="{StaticResource WithoutSwipeTemplate}" />
                </OnPlatform>
            </CollectionView.ItemTemplate>
        </CollectionView>
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.