问题描述
我有一个业务需求,需要构建一个包含多列的弹出菜单。该菜单将具有所有基本弹出行为,它必须在左侧有一个狭窄的静态列,其中包含 3 个按钮,然后在其旁边有常规的可滚动弹出菜单。此时是否可以在 xamarin 表单外壳中为弹出窗口执行完全自定义的布局?
解决方法
您可以使用 FlyoutContentTemplate
来做到这一点。
<Shell.FlyoutContentTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<StackLayout BackgroundColor="Purple">
<Button Text="home" />
<Button Text="dash" />
<Button Text="chat" />
</StackLayout>
<CollectionView
BindingContext="{x:Reference shell}"
IsGrouped="True"
ItemsSource="{Binding FlyoutItems}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label
FontSize="Large"
Text="{Binding Title}"
TextColor="Black" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</DataTemplate>
</Shell.FlyoutContentTemplate>