XLS0413在类型'TreeView'中找不到属性'ItemsSource'

时间:2018-11-04 21:52:59

标签: uwp-xaml

我将以下MainPage.xaml粘贴到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>

我遇到构建错误

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

智能提示也警告

无法识别或访问成员itemsource。

error list

数据源由

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

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

[更新]

我看到docs确实提到Windows.UI.XamlControls命名空间具有ItemsSource属性。命名空间位于Windows.UI.Xaml.Controls.dll,Windows.dll

但是,当我查看TreeView的元数据时,我看到的程序集是Windows.Foundation.UniversalApiContract

universal windows

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

intellisense

[更新]

SDK显示的版本错误

sdk version

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

我正在升级

[更新]

尝试一个新项目。它要求安装工具。 it asks to install tools

然后它会重新安装我刚刚删除的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命名空间

[更新]

好的,我很确定我现在处于地狱版本。 我刚刚更新到最新的预发行版 pre-releases

现在我得到

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\10\bin\10.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\10\bin\10.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

1 个答案:

答案 0 :(得分:2)

回到您的原始问题。 ItemsSource在文档中列为预览功能,请参见以下内容:

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

  2. TreeView.ItemsSource Property:设备家族Windows 10,版本1809(引入v10.0.17763.0)

是的,您的问题正在SDK上挂起。对于这个问题,实际上绑定到Treeview中的ItemsSource应该在17763上受支持。您需要将操作系统升级到1809,还需要安装17763 SDK。

我已经在一台装有17763的1809年机器中对此进行了测试,它可以正常工作。