首页 > 解决方案 > 创建具有动态子级的可重用组件

问题描述

我一直在寻找解决方案,但我不太清楚要搜索什么。我基本上想创建一个具有顶部和底部工具栏的可重用组件,如下所示:

<StackLayout>
    <StackLayout Orientation="Horizontal" VerticalOptions="Start" BackgroundColor="{StaticResource ToolbarColor}">
        <!-- Top toolbar content-->
    </StackLayout>

    <!- ??? -->

    <StackLayout Orientation="Horizontal" VerticalOptions="End" BackgroundColor="{StaticResource ToolbarColor}">
        <!-- Bottom toolbar content -->
    </StackLayout>
</StackLayout>

然后我希望能够像这样使用它:

<ToolbarComponent>
    <!-- Contents -->
</ToolbarComponent>

我不知道该怎么做,是 ToolbarComponent 的标记,我在哪里放 ??? 是,以便我指定的页面内容被插入其中?

标签: c#wpf

解决方案


要做的事情是为工具栏创建两个单独的用户控件。

然后像这样使用它们。

<StackLayout>
    <controls:TopToolbar/>

    <!-- Contents -->

    <controls:BottomToolbar>
</StackLayout>

推荐阅读