XLS0413 在“TreeView"类型中找不到“ItemsSource"属性 [英] XLS0413 The property 'ItemsSource' was not found in type 'TreeView'

查看:29
本文介绍了XLS0413 在“TreeView"类型中找不到“ItemsSource"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下 MainPage.xaml 粘贴到

数据源由

给出

使用 System.Collections.ObjectModel;使用 Windows.UI.Xaml.Controls;//空白页项目模板记录在 https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409命名空间 jtUFlow{公共密封部分类 MainPage : Page{私有 ObservableCollectionDataSource = new ObservableCollection();公共主页(){this.InitializeComponent();数据源 = GetDessertData();}私有 ObservableCollection获取甜点数据(){var list = new ObservableCollection();项目风味类别 = 新项目(){Name = "口味",儿童 ={new Item() { Name = "Vanilla" },new Item() { Name = "Strawberry" },新项目(){名称=巧克力"}}};Item toppingsCategory = new Item(){Name = "Toppings",儿童 ={新物品(){Name = "糖果",儿童 ={new Item() { Name = "巧克力" },new Item() { Name = "Mint" },new Item() { Name = "Sprinkles" }}},新物品(){Name = "水果",儿童 ={new Item() { Name = "Mango" },new Item() { Name = "Peach" },new Item() { Name = "Kiwi" }}},新物品(){Name = "浆果",儿童 ={new Item() { Name = "Strawberry" },new Item() { Name = "Blueberry" },新项目(){名称=黑莓"}}}}};list.Add(flavorsCategory);列表.添加(浇头类别);退货清单;}//按钮事件处理程序...}公共类项目{公共字符串名称{获取;放;}公共 ObservableCollection儿童{得到;放;} = new ObservableCollection();公共覆盖字符串 ToS​​tring(){返回名称;}}}

我安装的唯一 Nuget 包是

Microsoft.NETCore.UniversalWindowsPlatform v6.1.9

我的配置是调试 x86,并检查了构建和部署

最小和目标版本是 17134

我的操作系统是 Windows 10 版本 1803 17134.376

[更新]

我看到了

Intellisense 认为我正在使用 Windows.UI.Xaml.Controls.Treeview 但似乎不需要使用

[更新]

SDK 显示错误版本

编辑项目文件中的版本导致错误

我正在重新升级

[更新]

正在尝试一个新项目.它要求安装工具.

然后它重新安装我刚刚删除的 SDK 17134!

[更新]

我已经安装了 Microsoft.UI.Xaml 并将 XAML 更改为引用

xmlns:Custom="using:Microsoft.UI.Xaml.Controls"

我现在可以无错误地构建,但应用程序崩溃了.

 {Windows.UI.Xaml.UnhandledExceptionEventArgs}异常:{Windows.UI.Xaml.Markup.XamlParseException:找不到与此错误代码关联的文本.找不到名称/键为 TreeViewItemMinHeight 的资源 [行:1569 位置:38]}处理:假消息:找不到名称/键为 TreeViewItemMinHeight 的资源 [行:1569 位置:38]"本机视图:要检查本机对象,请启用本机代码调试.

我认为这是因为 DataTemplate 位于 Windows.UI.Xaml 命名空间而不是 Microsoft.UI.Xaml 命名空间

[更新]

好的,我很确定我现在处于版本地狱中.我刚刚更新到最新的预发布

现在我明白了

Microsoft.UI.Xaml nuget 包需要 TargetPlatformVersion >= 10.0.17763.0(当前项目为 17134)

解决了这个问题.现在我有

无法使用其输入参数初始化CompileXaml"任务.jtUFlow C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets

CompileXaml"任务不支持EnableTypeInfoReflection"参数.验证该参数是否存在于任务中,并且它是一个可设置的公共实例属性.jtUFlow C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets 335

Severity Code 描述 Project File Line Suppression State警告 NU1603 Microsoft.NETCore.UniversalWindowsPlatform 6.2.0-preview1-26926-04 取决于 Microsoft.Net.Native.Compiler (>= 2.2.0-rel-26924-00) 但 Microsoft.Net.Native.Compiler 2.2.0-rel-26924-00 未找到.Microsoft.Net.Native.Compiler 2.2.0-rel-26924-01 的近似最佳匹配已解决.jtUFlow D:\dev\jtUflow\jtUFlow\jtUFlow\jtUFlow.csproj 1

[更新]

我回到最新的稳定 Nuget 包,并注意到我忘记将以下内容放入 App.xaml

<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/></Application.Resources>

现在 MainPage.xaml 状态

Visual Studio 需要更新版本的 WINdows 才能显示此内容.请更新到 Windows 10 版本 1809 ( 10.0.17763.0) 或更高版本

解决方案

回到你最初的问题.ItemsSource 在文档中列为预览功能,请参阅以下内容:

  1. TreeView:(Preview) 数据绑定到 TreeView 和 TreeViewItem 上的 ItemsSource 属性

  2. TreeView.ItemsSource 属性:设备系列 Windows 10,版本 1809(引入 v10.0.17763.0)

所以是的,您的问题在 SDK 上悬而未决.对于这个问题,实际上绑定到Treeview中的ItemsSource应该支持17763.你需要将你的操作系统升级到1809并安装17763 SDK.

我已经在一台安装了 17763 的 1809 机器上测试了这个,它没有问题.

I have the following MainPage.xaml pasted in from the docs

<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>

I get build errors

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 also warns

the member itemsource is not recognised or accessible.

The datasource is given by

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;
        }
    }

}

The only Nuget package I have installed is

Microsoft.NETCore.UniversalWindowsPlatform v6.1.9

My configuration is Debug x86 with build and deploy checked

Min and Target version is 17134

My operating system is Windows 10 version 1803 17134.376

[Update]

I see the docs do mention that Windows.UI.XamlControls namespace has the ItemsSource property. The namespace is in Windows.UI.Xaml.Controls.dll, Windows.dll

However when I look at the metadata for TreeView I see the assembly is Windows.Foundation.UniversalApiContract

Intellisense thinks that I am using Windows.UI.Xaml.Controls.Treeview yet the using appears not needed

[Update]

The SDK is showing the wrong version

Editing the version in the project file causes errors

I am re-upgrading

[Update]

Attempting a new project. It asks to install tools.

Then it reinstalls SDK 17134 that I just removed !

[Update]

I have installed Microsoft.UI.Xaml and changed the XAML to reference

xmlns:Custom="using:Microsoft.UI.Xaml.Controls"

I am able to build without errors now but the app crashes.

    {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.

I expect this is because DataTemplate is in the Windows.UI.Xaml namespace instead of the Microsoft.UI.Xaml namespace

[Update]

OK, I am pretty sure I am in version hell now. I just updated to the latest pre-releases

Now I get

Microsoft.UI.Xaml nuget package requires TargetPlatformVersion >= 10.0.17763.0 (current project is 17134)    

Fixed that. Now I have

The "CompileXaml" task could not be initialized with its input parameters.  jtUFlow C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets   

and

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\10\bin\10.0.17763.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets   335 

and

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

[Update]

I rewound to latest stable Nuget packages and noticed that I forgot to put the following inside App.xaml

<Application.Resources>
    <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>

Now MainPage.xaml states

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

解决方案

Back to your original question. The ItemsSource is listed in the doc as preview feature, see the following:

  1. TreeView:(Preview) Data binding to the ItemsSource property on TreeView and TreeViewItem

  2. TreeView.ItemsSource Property:Device family Windows 10, version 1809 (introduced v10.0.17763.0)

So yes your problem is pending on SDK. For this question, actually binding to the ItemsSource in Treeview should support on 17763. You need to upgrade your OS to 1809 and also install 17763 SDK.

And I have tested this in a 1809 machine which has 17763 installed, it works without problem.

这篇关于XLS0413 在“TreeView"类型中找不到“ItemsSource"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆