XLS0413 The property 'ItemsSource' was not found in type 'TreeView'

房东的猫 提交于 2019-12-11 09:29:00

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/53145869/xls0413the-property-itemssource-was-not-found-in-type-treeview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!