Prism是否支持编译绑定

问题描述 投票:0回答:1

我不清楚棱镜中是否支持编译装订。它是一项非常出色的功能,可以避免反射并加快页面的加载速度。

希望Brian Lagunas或Dan Siegel会回答这一问题。

有人可以澄清棱镜中是否支持编译绑定,以及如何做到或神奇地做到这一点,或者我们需要手动设置bindingcontext。

答案会受到任何人的赞赏吗?

已更新点头样品

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="PrismCompiledBinding.Views.MainPage"
                 xmlns:d="http://xamarin.com/schemas/2014/forms/design"
                 xmlns:models="clr-namespace:PrismCompiledBinding.Models">

        <!--x:DataType="ViewModel:MainPageViewModel"-->
        <!--mc:Ignorable="d"-->
        <ContentPage.Content>
            <ListView
                ItemsSource="{Binding Monkeys}"
                SeparatorVisibility="None"
                VerticalOptions="FillAndExpand">
                <ListView.ItemTemplate>
                    <DataTemplate  x:DataType="models:Monkey">
                        <ViewCell>
                            <StackLayout
                                Padding="20,10,0,10"
                                Orientation="Horizontal"
                                Spacing="20"
                                VerticalOptions="FillAndExpand">

                                <Label
                                    FontSize="Medium"
                                    Text="{Binding Name}"
                                    TextColor="Black"
                                    VerticalOptions="Center" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </ContentPage.Content>
    </ContentPage>

    using System.Collections.ObjectModel;
    using Prism.Navigation;
    using PrismCompiledBinding.Models;

    namespace PrismCompiledBinding.ViewModels
    {
        public class MainPageViewModel : ViewModelBase
        {
            public MainPageViewModel(INavigationService navigationService)
                : base(navigationService)
            {
                Monkeys = GetMonkeys();
            }


            private ObservableCollection<Monkey> monkeys;

            public ObservableCollection<Monkey> Monkeys
            {
                get => monkeys;
                set => SetProperty(ref monkeys, value);
            }

            private ObservableCollection<Monkey> GetMonkeys()
            {
                ObservableCollection<Monkey> list=new ObservableCollection<Monkey>();
                list.Add(new Monkey
                {
                    Name = "Baboon",
                    Location = "Africa & Asia",
                    Details =
                        "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.",
                });
                list.Add(new Monkey
                {
                    Name = "Capuchin Monkey",
                    Location = "Central & South America",
                    Details =
                        "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.",
                });
                return list;
            }
        }
    }

       public class Monkey
        {
            public string Name { get; set; }
            public string Location { get; set; }
            public string Details { get; set; }
        }

感谢

xamarin.forms prism
1个回答
0
投票

是的已编译绑定Prism正常工作。

我使用Prism版本7.2.0.1422和Xamarin.Forms 4.2.0.848062进行了特殊测试。

我关注了this tutorial

© www.soinside.com 2019 - 2024. All rights reserved.