[英]How to create a tree view in uwp xaml
hi guys I have created a Tree view but I can't print the content in the tree view my code is `大家好,我创建了一个树视图,但我无法打印树视图中的内容,我的代码是`
<TreeView x:Name="treeview" Grid.Row="2" Background="Blue" HorizontalAlignment="Center">
<TreeView.RootNodes >
<TreeViewNode Content="colur">
<TreeViewNode.Children>
<TreeViewNode Content="blue"></TreeViewNode>
<TreeViewNode Content="green"></TreeViewNode>
<TreeViewNode Content="red"></TreeViewNode>
</TreeViewNode.Children>
</TreeViewNode>
</TreeView.RootNodes>
</TreeView>
` `
This is because the UWP application can't find the TreeViewNode
class as it is a WinUI control.这是因为 UWP 应用程序无法找到TreeViewNode
class,因为它是一个 WinUI 控件。 Please use the TreeView Control from the WinUI library in your UWP aplication.请在您的 UWP 应用程序中使用 WinUI 库中的 TreeView 控件。
In the Solution Explorer , right click on your project name and select Manage NuGet Packages .在Solution Explorer中,右键单击您的项目名称和 select Manage NuGet Packages 。
In the NuGet Package Manager , select the Browse tab and search for Microsoft.UI.Xaml or WinUI .在NuGet Package 管理器中,select 的浏览选项卡并搜索Microsoft.UI.Xaml或WinUI 。 Install which Windows UI Library NuGet Packages you want to use.安装您要使用的 Windows UI 库 NuGet 包。 I'm using WinUI 2.8.1我正在使用 WinUI 2.8.1
Add the Windows UI (WinUI) Theme Resources to your App.xaml file.将Windows UI (WinUI) 主题资源添加到您的App.xaml文件中。
<Application.Resources> <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> </Application.Resources>
Add a reference to the WinUI package to both XAML pages and/or code-behind pages .将对 WinUI package 的引用添加到XAML 页面和/或代码隐藏页面。
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
Change your Xaml code to use the TreeView control from WinUI library.更改 Xaml 代码以使用 WinUI 库中的 TreeView 控件。
Like this:像这样:
<muxc:TreeView x:Name="treeview" Grid.Row="2" Background="Blue" HorizontalAlignment="Center">
<muxc:TreeView.RootNodes >
<muxc:TreeViewNode Content="colur">
<muxc:TreeViewNode.Children>
<muxc:TreeViewNode Content="blue"></muxc:TreeViewNode>
<muxc:TreeViewNode Content="green"></muxc:TreeViewNode>
<muxc:TreeViewNode Content="red"></muxc:TreeViewNode>
</muxc:TreeViewNode.Children>
</muxc:TreeViewNode>
</muxc:TreeView.RootNodes>
</muxc:TreeView>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.