Xamarin.forms ContentView作为资源字典
可重复使用的布局可以在Xamarin.forms ContentView作为资源字典,xamarin.forms,Xamarin.forms,可重复使用的布局可以在ContentView中的一个单独的文件中使用,使用方式如下: <StackLayout> <local:MyContentView/> </StackLayout> 但是,如果我想将ContentView作为资源字典放在同一个文件中并使用它,是否可能?。这就是我想要的: <ContentPage.Resources> <ResourceDictionary> <Co
ContentView
中的一个单独的文件中使用,使用方式如下:
<StackLayout>
<local:MyContentView/>
</StackLayout>
但是,如果我想将ContentView作为资源字典放在同一个文件中并使用它,是否可能?。这就是我想要的:
<ContentPage.Resources>
<ResourceDictionary>
<ContentView x:Key="MyContentView">
<!--Some Views-->
</ContentView>
</ResourceDictionary>
</ContentPage.Resources>
那么如何在StackLayout中使用此
键?在ResourceDictionary中定义ControlTemplate并在Xaml中使用它:
<ContentPage.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MyContentView">
<Label Text="tttttt" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ControlTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
<!-- Place new controls here -->
<ContentView ControlTemplate="{StaticResource MyContentView}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>