我有一个在 Uno 平台上运行的 WinUI3 应用程序,我正在尝试实现 TreeView。 我尝试了在互联网上找到的几个示例,但没有一个效果很好。唯一已编译的版本是来自 unoplatform github 的版本:https://github.com/unoplatform/uno/blob/master/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/TreeView/TreeViewBasics.xaml
这里我们可以看到xaml和cs代码:
XAML:
<Page
x:Class="UITests.Microsoft_UI_Xaml_Controls.TreeView.TreeViewBasics"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:UITests.Microsoft_UI_Xaml_Controls.TreeView"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid>
<muxc:TreeView>
<muxc:TreeView.RootNodes>
<muxc:TreeViewNode x:Name="RootNode" Content="Flavors" IsExpanded="True">
<muxc:TreeViewNode.Children>
<muxc:TreeViewNode Content="Vanilla" />
<muxc:TreeViewNode Content="Strawberry" />
<muxc:TreeViewNode Content="Chocolate">
<muxc:TreeViewNode.Children>
<muxc:TreeViewNode Content="Dark" />
<muxc:TreeViewNode Content="White" />
</muxc:TreeViewNode.Children>
</muxc:TreeViewNode>
<muxc:TreeViewNode Content="Caramel" />
</muxc:TreeViewNode.Children>
</muxc:TreeViewNode>
</muxc:TreeView.RootNodes>
</muxc:TreeView>
</Grid>
</Page>
cs:
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml.Controls;
namespace UITests.Microsoft_UI_Xaml_Controls.TreeView
{
[Sample("TreeView")]
public sealed partial class TreeViewBasics : Page
{
public TreeViewBasics()
{
this.InitializeComponent();
}
}
}
所以,我真的很想知道是否有人能够正确使用这段代码以及它是否工作正常。当我运行它时,它没有出现任何东西。
我还观察到,他们在这里使用 Uno.UI.Samples.Controls,我担心这可能是我的问题的根源,但我无法使用它,因为我实际上使用 Uno.WinUI 并且如果我安装了两个块包vs 抱怨它。
如果有人能回答我的一些疑问,我会非常高兴。
谢谢你。
TreeView 显示在 Uno Platform Playground 上: https://playground.platform.uno/#treeview