若界面使用了绑定,预览界面通常不会加载相关数据并显示,此时在预览界面中调节UI,可使用Design Time Data。
添加空间引用:
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:viewmodels="clr-namespace:CompiledBindingsSample.ViewModels"
xmlns:models="clr-namespace:CompiledBindingsSample.Models"
x:Class="CompiledBindingsSample.MainPage"
x:DataType="viewmodels:MainPageVM">
<ContentPage.BindingContext>
<viewmodels:MainPageVM/>
</ContentPage.BindingContext>
<StackLayout>
<ListView ItemsSource="{Binding Books}">
<d:ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>One Item</x:String>
<x:String>Two Item</x:String>
<x:String>Three Item</x:String>
<x:String>Four Item</x:String>
<x:String>Five Item</x:String>
</x:Array>
</d:ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:Book">
<TextCell Text="{Binding Title}"
d:Text="{Binding .}"
Detail="{Binding Publisher}"
d:Detail="Detail Info"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
channel9: Design Time Data