XLS0413 Свойство ItemsSource не найдено в типе TreeView - PullRequest
0 голосов
/ 05 ноября 2018

У меня есть следующий 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 также предупреждает

источник элементов-членов не распознан или недоступен.

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

[Update]

Я вижу, что в документах упоминается, что пространство имен 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

Редактирование версии в файле проекта вызывает ошибки

Я обновляю

[Update]

Попытка нового проекта. Он просит установить инструменты. it asks to install tools

Затем переустанавливает SDK 17134, который я только что удалил!

[Update]

Я установил 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

[Update]

Хорошо, я почти уверен, что сейчас в адской версии. Я только что обновился до последних предварительных выпусков 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

[Обновление] * +1101 *

Я перемотал на последние стабильные пакеты 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 голосов
/ 06 ноября 2018

Вернуться к исходному вопросу. ItemsSource указан в документе как функция предварительного просмотра, см. Следующее:

  1. TreeView :( Preview) Привязка данных к свойству ItemsSource в TreeView и TreeViewItem

  2. Свойство TreeView.ItemsSource : семейство устройств Windows 10, версия 1809 (введено 10.0.17763.0)

Так что да, ваша проблема находится на рассмотрении в SDK. Для этого вопроса на 17763 должна поддерживаться привязка к ItemsSource в Treeview. Вам нужно обновить ОС до 1809, а также установить 17763 SDK.

И я проверил это на машине 1809, на которой установлено 17763, она работает без проблем.

...