Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms ContentView作为资源字典_Xamarin.forms - Fatal编程技术网

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>