https://blog.csdn.net/weixin_50900104/article/details/127092798

page.xaml

<ListView ItemsSource="{x:Static local:VersionUpdateModel.All}"
                   RowHeight="{StaticResource rowHeight}"
              ItemSelected="OnListViewItemSelected">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="15, 5, 0, 5"
                                 Orientation="Horizontal"
                                 Spacing="240">

                            <StackLayout Padding="5, 0, 0, 0"
                                     VerticalOptions="Center">
                                     //标题
                                <Label Text="{Binding Title}"
                                   FontAttributes="Bold"
                                   FontSize="16" ></Label>
                                  //时间
                                <StackLayout Orientation="Horizontal"
                                         Spacing="0">
                                    <Label Text="{Binding Description,
                                       StringFormat='{0:X2}'}" ></Label>

                                </StackLayout>

                            </StackLayout>
                            //箭头
                            <Label FontFamily="icon"
                               Grid.Column="2"
                               FontSize="16"
                               FontAttributes="Bold"
                               HorizontalOptions="End"
                               HorizontalTextAlignment="Center"
                               Text=""
                               TextColor="Black"
                               VerticalOptions="CenterAndExpand" ></Label>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

page.xaml.cs


 private async void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs args)
    {
        (sender as ListView).SelectedItem = null;

        if (args.SelectedItem != null)
        {
            VersionUpdateModel pageData = args.SelectedItem as VersionUpdateModel;
            Page page = (Page)Activator.CreateInstance(pageData.Type);//获取路径
            Application.Current.MainPage.Navigation.PushModalAsync(page);//跳转
        }
    }

model


public class VersionUpdateModel
    {
        public  VersionUpdateModel(Type type, string title, string description)
        {
            Type = type;
             Title = title;
            Description = description;
        }

        public Type Type { private set; get; }

        public string Title { private set; get; }

        public string Description { private set; get; }

        static VersionUpdateModel()
        {
            All = new List<VersionUpdateModel>
            {
                new VersionUpdateModel(typeof(VersionContentPage), " 8.2.1 主要更新",
                                      "2022-9-21"),

                new VersionUpdateModel(typeof(VersionContentPage), " 8.2.2 主要更新",
                                      "2022-9-22"),

                new VersionUpdateModel(typeof(VersionContentPage), " 8.2.3 主要更新",
                                      "2022-9-23"),

                new VersionUpdateModel(typeof(VersionContentPage), " 8.2.4 主要更新",
                                      "2022-9-28"),

            };
        }

        public static IList<VersionUpdateModel> All { private set; get; }
    }
文档更新时间: 2023-11-18 13:19   作者:admin