XLS0413 在类型 'TreeView' 中找不到 属性 'ItemsSource'
XLS0413 The property 'ItemsSource' was not found in type 'TreeView'
中粘贴了以下 MainPage.xaml
<Page
x:Class="jtUFlow.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:jtUFlow"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Windows.UI.Xaml.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="100">
<SplitView IsPaneOpen="True"
DisplayMode="Inline"
OpenPaneLength="296">
<SplitView.Pane>
<TreeView ItemsSource="{x:Bind DataSource}">
<TreeView.ItemTemplate>
<DataTemplate x:DataType="local:Item">
<TreeViewItem ItemsSource="{x:Bind Children}"
Content="{x:Bind Name}"/>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</SplitView.Pane>
<StackPanel Grid.Column="1" Margin="12,0">
<TextBlock Text="Your flavor selections:" Style="{StaticResource CaptionTextBlockStyle}"/>
<TextBlock x:Name="FlavorList" Margin="0,0,0,12"/>
<TextBlock Text="Your topping selections:" Style="{StaticResource CaptionTextBlockStyle}"/>
<TextBlock x:Name="ToppingList"/>
</StackPanel>
</SplitView>
</Grid>
</Page>
我遇到构建错误
Unknown member 'ItemsSource' on element 'TreeView'
XLS0413 The property 'ItemsSource' was not found in type 'TreeView'.
XDG0012 The member "ItemsSource" is not recognized or is not accessible.
XDG0012 The member "ItemTemplate" is not recognized or is not accessible.
XLS0415 The attachable property 'ItemTemplate' was not found in type
XLS0413 The property 'ItemsSource' was not found in type 'TreeViewItem'.
intellisense 也会发出警告
无法识别或访问成员项目源。
数据源由
提供
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace jtUFlow
{
public sealed partial class MainPage : Page
{
private ObservableCollection<Item> DataSource = new ObservableCollection<Item>();
public MainPage()
{
this.InitializeComponent();
DataSource = GetDessertData();
}
private ObservableCollection<Item> GetDessertData()
{
var list = new ObservableCollection<Item>();
Item flavorsCategory = new Item()
{
Name = "Flavors",
Children =
{
new Item() { Name = "Vanilla" },
new Item() { Name = "Strawberry" },
new Item() { Name = "Chocolate" }
}
};
Item toppingsCategory = new Item()
{
Name = "Toppings",
Children =
{
new Item()
{
Name = "Candy",
Children =
{
new Item() { Name = "Chocolate" },
new Item() { Name = "Mint" },
new Item() { Name = "Sprinkles" }
}
},
new Item()
{
Name = "Fruits",
Children =
{
new Item() { Name = "Mango" },
new Item() { Name = "Peach" },
new Item() { Name = "Kiwi" }
}
},
new Item()
{
Name = "Berries",
Children =
{
new Item() { Name = "Strawberry" },
new Item() { Name = "Blueberry" },
new Item() { Name = "Blackberry" }
}
}
}
};
list.Add(flavorsCategory);
list.Add(toppingsCategory);
return list;
}
// Button event handlers...
}
public class Item
{
public string Name { get; set; }
public ObservableCollection<Item> Children { get; set; } = new ObservableCollection<Item>();
public override string ToString()
{
return Name;
}
}
}
我安装的唯一 Nuget 包是
Microsoft.NETCore.UniversalWindowsPlatform v6.1.9
我的配置是 Debug x86,并检查了构建和部署
最低和目标版本为 17134
我的操作系统是Windows10版本1803 17134.376
[更新]
我看到 docs 提到 Windows.UI.XamlControls 命名空间有 ItemsSource 属性。命名空间在 Windows.UI.Xaml.Controls.dll、Windows.dll
然而,当我查看 TreeView 的元数据时,我看到程序集是 Windows.Foundation.UniversalApiContract
Intellisense 认为我正在使用 Windows.UI.Xaml.Controls.Treeview 但似乎不需要使用
[更新]
SDK 显示错误版本
编辑项目文件中的版本导致错误
我正在重新升级
[更新]
正在尝试一个新项目。它要求安装工具。
然后它会重新安装我刚刚删除的 SDK 17134!
[更新]
我已经安装了 Microsoft.UI.Xaml 并将 XAML 更改为引用
xmlns:Custom="using:Microsoft.UI.Xaml.Controls"
我现在可以正确构建,但应用程序崩溃了。
{Windows.UI.Xaml.UnhandledExceptionEventArgs}
Exception: {Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.
Cannot find a Resource with the Name/Key TreeViewItemMinHeight [Line: 1569 Position: 38]}
Handled: false
Message: "Cannot find a Resource with the Name/Key TreeViewItemMinHeight [Line: 1569 Position: 38]"
Native View: To inspect the native object, enable native code debugging.
我预计这是因为 DataTemplate 在 Windows.UI.Xaml 命名空间而不是 Microsoft.UI.Xaml 命名空间
[更新]
好的,我很确定我现在正处于版本地狱中。
我刚刚更新到最新的预发布版本
现在我明白了
Microsoft.UI.Xaml nuget package requires TargetPlatformVersion >= 10.0.17763.0 (current project is 17134)
已修复。
现在我有
The "CompileXaml" task could not be initialized with its input parameters. jtUFlow C:\Program Files (x86)\Windows Kits\bin.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets
和
The "EnableTypeInfoReflection" parameter is not supported by the "CompileXaml" task. Verify the parameter exists on the task, and it is a settable public instance property. jtUFlow C:\Program Files (x86)\Windows Kits\bin.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets 335
和
Severity Code Description Project File Line Suppression State
Warning NU1603 Microsoft.NETCore.UniversalWindowsPlatform 6.2.0-preview1-26926-04 depends on Microsoft.Net.Native.Compiler (>= 2.2.0-rel-26924-00) but Microsoft.Net.Native.Compiler 2.2.0-rel-26924-00 was not found. An approximate best match of Microsoft.Net.Native.Compiler 2.2.0-rel-26924-01 was resolved. jtUFlow D:\dev\jtUflow\jtUFlow\jtUFlow\jtUFlow.csproj 1
[更新]
我回到最新的稳定 Nuget 包并注意到我忘记将以下内容放入 App.xaml
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
现在 MainPage.xaml 状态
Visual Studio requires a newer version of WIndows to display this content.
Please update to Windows 10, version 1809 ( 10.0.17763.0) or later
回到你原来的问题。 ItemsSource 在文档中作为预览功能列出,请参阅以下内容:
TreeView:(预览)数据绑定到 TreeView 和 TreeViewItem
上的 ItemsSource 属性
TreeView.ItemsSource Property:设备系列Windows10,版本1809(引入v10.0.17763.0)
是的,您的问题在 SDK 上悬而未决。对于这个问题,实际绑定到Treeview中的ItemsSource应该支持17763。你需要将你的OS升级到1809并安装17763 SDK。
而且我已经在安装了 17763 的 1809 机器上测试了它,它没有问题。
<Page
x:Class="jtUFlow.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:jtUFlow"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Windows.UI.Xaml.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="100">
<SplitView IsPaneOpen="True"
DisplayMode="Inline"
OpenPaneLength="296">
<SplitView.Pane>
<TreeView ItemsSource="{x:Bind DataSource}">
<TreeView.ItemTemplate>
<DataTemplate x:DataType="local:Item">
<TreeViewItem ItemsSource="{x:Bind Children}"
Content="{x:Bind Name}"/>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</SplitView.Pane>
<StackPanel Grid.Column="1" Margin="12,0">
<TextBlock Text="Your flavor selections:" Style="{StaticResource CaptionTextBlockStyle}"/>
<TextBlock x:Name="FlavorList" Margin="0,0,0,12"/>
<TextBlock Text="Your topping selections:" Style="{StaticResource CaptionTextBlockStyle}"/>
<TextBlock x:Name="ToppingList"/>
</StackPanel>
</SplitView>
</Grid>
</Page>
我遇到构建错误
Unknown member 'ItemsSource' on element 'TreeView'
XLS0413 The property 'ItemsSource' was not found in type 'TreeView'.
XDG0012 The member "ItemsSource" is not recognized or is not accessible.
XDG0012 The member "ItemTemplate" is not recognized or is not accessible.
XLS0415 The attachable property 'ItemTemplate' was not found in type
XLS0413 The property 'ItemsSource' was not found in type 'TreeViewItem'.
intellisense 也会发出警告
无法识别或访问成员项目源。
数据源由
提供using System.Collections.ObjectModel;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace jtUFlow
{
public sealed partial class MainPage : Page
{
private ObservableCollection<Item> DataSource = new ObservableCollection<Item>();
public MainPage()
{
this.InitializeComponent();
DataSource = GetDessertData();
}
private ObservableCollection<Item> GetDessertData()
{
var list = new ObservableCollection<Item>();
Item flavorsCategory = new Item()
{
Name = "Flavors",
Children =
{
new Item() { Name = "Vanilla" },
new Item() { Name = "Strawberry" },
new Item() { Name = "Chocolate" }
}
};
Item toppingsCategory = new Item()
{
Name = "Toppings",
Children =
{
new Item()
{
Name = "Candy",
Children =
{
new Item() { Name = "Chocolate" },
new Item() { Name = "Mint" },
new Item() { Name = "Sprinkles" }
}
},
new Item()
{
Name = "Fruits",
Children =
{
new Item() { Name = "Mango" },
new Item() { Name = "Peach" },
new Item() { Name = "Kiwi" }
}
},
new Item()
{
Name = "Berries",
Children =
{
new Item() { Name = "Strawberry" },
new Item() { Name = "Blueberry" },
new Item() { Name = "Blackberry" }
}
}
}
};
list.Add(flavorsCategory);
list.Add(toppingsCategory);
return list;
}
// Button event handlers...
}
public class Item
{
public string Name { get; set; }
public ObservableCollection<Item> Children { get; set; } = new ObservableCollection<Item>();
public override string ToString()
{
return Name;
}
}
}
我安装的唯一 Nuget 包是
Microsoft.NETCore.UniversalWindowsPlatform v6.1.9
我的配置是 Debug x86,并检查了构建和部署
最低和目标版本为 17134
我的操作系统是Windows10版本1803 17134.376
[更新]
我看到 docs 提到 Windows.UI.XamlControls 命名空间有 ItemsSource 属性。命名空间在 Windows.UI.Xaml.Controls.dll、Windows.dll
然而,当我查看 TreeView 的元数据时,我看到程序集是 Windows.Foundation.UniversalApiContract
Intellisense 认为我正在使用 Windows.UI.Xaml.Controls.Treeview 但似乎不需要使用
[更新]
SDK 显示错误版本
编辑项目文件中的版本导致错误
我正在重新升级
[更新]
正在尝试一个新项目。它要求安装工具。
然后它会重新安装我刚刚删除的 SDK 17134!
[更新]
我已经安装了 Microsoft.UI.Xaml 并将 XAML 更改为引用
xmlns:Custom="using:Microsoft.UI.Xaml.Controls"
我现在可以正确构建,但应用程序崩溃了。
{Windows.UI.Xaml.UnhandledExceptionEventArgs}
Exception: {Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.
Cannot find a Resource with the Name/Key TreeViewItemMinHeight [Line: 1569 Position: 38]}
Handled: false
Message: "Cannot find a Resource with the Name/Key TreeViewItemMinHeight [Line: 1569 Position: 38]"
Native View: To inspect the native object, enable native code debugging.
我预计这是因为 DataTemplate 在 Windows.UI.Xaml 命名空间而不是 Microsoft.UI.Xaml 命名空间
[更新]
好的,我很确定我现在正处于版本地狱中。
我刚刚更新到最新的预发布版本
现在我明白了
Microsoft.UI.Xaml nuget package requires TargetPlatformVersion >= 10.0.17763.0 (current project is 17134)
已修复。 现在我有
The "CompileXaml" task could not be initialized with its input parameters. jtUFlow C:\Program Files (x86)\Windows Kits\bin.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets
和
The "EnableTypeInfoReflection" parameter is not supported by the "CompileXaml" task. Verify the parameter exists on the task, and it is a settable public instance property. jtUFlow C:\Program Files (x86)\Windows Kits\bin.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets 335
和
Severity Code Description Project File Line Suppression State
Warning NU1603 Microsoft.NETCore.UniversalWindowsPlatform 6.2.0-preview1-26926-04 depends on Microsoft.Net.Native.Compiler (>= 2.2.0-rel-26924-00) but Microsoft.Net.Native.Compiler 2.2.0-rel-26924-00 was not found. An approximate best match of Microsoft.Net.Native.Compiler 2.2.0-rel-26924-01 was resolved. jtUFlow D:\dev\jtUflow\jtUFlow\jtUFlow\jtUFlow.csproj 1
[更新]
我回到最新的稳定 Nuget 包并注意到我忘记将以下内容放入 App.xaml
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
现在 MainPage.xaml 状态
Visual Studio requires a newer version of WIndows to display this content.
Please update to Windows 10, version 1809 ( 10.0.17763.0) or later
回到你原来的问题。 ItemsSource 在文档中作为预览功能列出,请参阅以下内容:
TreeView:(预览)数据绑定到 TreeView 和 TreeViewItem
上的 ItemsSource 属性
TreeView.ItemsSource Property:设备系列Windows10,版本1809(引入v10.0.17763.0)
是的,您的问题在 SDK 上悬而未决。对于这个问题,实际绑定到Treeview中的ItemsSource应该支持17763。你需要将你的OS升级到1809并安装17763 SDK。
而且我已经在安装了 17763 的 1809 机器上测试了它,它没有问题。