我已经从 Microsoft下载并打开了 Xamarin.Forms Shell 示例项目Xanimals,但它从 AppShell.xaml 抛出构建错误。
错误是:
错误 XLS0503 无法将“ShellContent”类型的值添加到“IList”类型的集合或字典中。Xaminals AppShell.xaml 135
错误 XLS0503 无法将“MenuItem”类型的值添加到“IList”类型的集合或字典中。Xaminals AppShell.xaml 158
无效类型:预期类型为“ShellSection”,实际类型为“ShellContent”。
无效类型:预期类型为“ShellSection”,实际类型为“MenuItem”。
我最初是在创建新的 Xamarin Shell 应用程序并遵循 Microsoft 的相应指南时发现这个问题的,其中他们的示例代码描述了将一些 ShellContent 元素直接放在应用程序的 AppShell.xaml 文件中的 FlyoutItem 下。
以下是 Microsoft Xanimals 示例项目中的相关代码部分:
<FlyoutItem Route="animals"
Title="Animals"
FlyoutDisplayOptions="AsMultipleItems">
<Tab Title="Domestic"
Route="domestic"
Icon="paw.png">
<ShellContent Route="cats"
Style="{StaticResource DomesticShell}"
Title="Cats"
Icon="cat.png"
ContentTemplate="{DataTemplate views:CatsPage}" />
<ShellContent Route="dogs"
Style="{StaticResource DomesticShell}"
Title="Dogs"
Icon="dog.png"
ContentTemplate="{DataTemplate views:DogsPage}" />
</Tab>
<ShellContent Route="monkeys"
Style="{StaticResource MonkeysShell}"
Title="Monkeys"
Icon="monkey.png"
ContentTemplate="{DataTemplate views:MonkeysPage}" />
<ShellContent Route="elephants"
Style="{StaticResource ElephantsShell}"
Title="Elephants"
Icon="elephant.png" …
Run Code Online (Sandbox Code Playgroud) 这是我想要实现的目标的直观想法:
我希望左侧和右侧的所有按钮都垂直对齐,无论 TreeViewItem 位于树中的哪个位置。我在实现这种效果时遇到了困难,同时也让标题以典型的嵌套方式缩进。
我最近的尝试涉及修改 TreeViewItem 模板;将按钮放在跨越主网格中所有列的 DockPanel 中(停靠在左侧或右侧),将扩展器和标题放在中间列中,并使 ItemsPresenter (ItemsHost) 跨越下一行上的所有列。这使得所有内容都对齐,包括标题内容。
这是我目前的 TreeViewItem 样式的简化版本:
<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="Transparent" Height="16" Padding="5,5,5,5" Width="16">
<Path x:Name="ExpandPath" Data="{StaticResource TreeArrow}" Fill="{StaticResource TreeViewItem.TreeArrow.Static.Fill}" Stroke="{StaticResource TreeViewItem.TreeArrow.Static.Stroke}">
<Path.RenderTransform>
<RotateTransform Angle="135" CenterY="3" CenterX="3"/>
</Path.RenderTransform>
</Path>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="RenderTransform" TargetName="ExpandPath">
<Setter.Value>
<RotateTransform Angle="180" CenterY="3" CenterX="3"/>
</Setter.Value>
</Setter>
<Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource TreeViewItem.TreeArrow.Static.Checked.Fill}"/>
<Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource …
Run Code Online (Sandbox Code Playgroud)