dullman
Topic Author
Posts: 4
Joined: 10 Sep 2017, 21:00

Unity NoesisException: ItemsPanel visual tree root must be a Panel with no children

25 Mar 2018, 20:20

Hello I have a xaml file for game view and wanted to create screen like inventory, but gets this error, but don't get why since my wrapPanel is Panel and without children, so probably is somewhere I make a mistake since to be truthful I only learn wpf using noesis so some ideas I might get wrong. Also if I did not include ListBox in Window class user control the error does not happen.

<game:Window x:Name="ShopWindow" Grid.ColumnSpan="3" Grid.RowSpan="3" Height="800" Width="900">
      <game:Window.HeaderContent>
        <TextBlock Grid.Column="0" Text="Welcome To Shop" TextAlignment="Center" TextWrapping="Wrap" FontSize="35" VerticalAlignment="Center"/>
      </game:Window.HeaderContent>
      <game:Window.WindowContent>
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="60"/>
            <ColumnDefinition Width="*"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="60"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
            <ComboBox ItemsSource="{Binding ElementName=CharactersBuildingList, Path=DataContext.PlayerBuildings}" Name="ShopWindowSelectBuilding" SelectedItem="{Binding ElementName=BuildingsListBox, Path=SelectedItem}"  Style="{StaticResource CustomComboBox}" Width="180">
              <ComboBox.ItemTemplate>
                <DataTemplate>
                  <WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Vertical">
                    <TextBlock Text="{Binding BuildingName}" TextWrapping="Wrap"/>
                    <TextBlock Text="{Binding BuildingType}" TextWrapping="Wrap"/>
                  </WrapPanel>
                </DataTemplate>
              </ComboBox.ItemTemplate>
            </ComboBox>
            <ComboBox ItemsSource="{Binding ElementName=CharactersBuildingList, Path=DataContext.PlayerBuildingsCharacters}" Name="ShopWindowSelectCharacter" SelectedItem="{Binding ElementName=CharactersBuildingList, Path=SelectedItem}"  Style="{StaticResource CustomComboBox}" Width="180">
              <ComboBox.ItemTemplate>
                <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name.FullName}" TextWrapping="Wrap"/>
                  </StackPanel>
                </DataTemplate>
              </ComboBox.ItemTemplate>
            </ComboBox>
          </StackPanel>

          <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical">
            <TextBlock Text="Character Items" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>

          </StackPanel>
          <ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{Binding ElementName=ShopWindowSelectCharacter, Path=SelectedItem.Inventory.Items}" >
            <ListBox.ItemsPanel>
              <ItemsPanelTemplate>
                <WrapPanel Width="380"/>
              </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
              <DataTemplate>
                <Grid>
                  <Border Height="96" Width="96" CornerRadius="8" BorderThickness="2" BorderBrush="{StaticResource NormalBdBrush}"/>
                  <TextBlock TextWrapping="Wrap" Text="{Binding Name}" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center" MaxWidth="60"/>
                  <TextBlock TextWrapping="Wrap" Text="{Binding Amount}" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" MaxWidth="60"/>
                </Grid>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </Grid>
      </game:Window.WindowContent>
    </game:Window>
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Unity NoesisException: ItemsPanel visual tree root must be a Panel with no children

27 Mar 2018, 17:30

Hi, I tried your xaml by changing the game:Window to a simple Grid, and using defualt ComboBox style instead of CustomComboBox resource and the xaml throws no errors.
Maybe the error is in the template of one of this objects.
Could you please attach Style+Template of game:Window and CustomComboBox?
 
dullman
Topic Author
Posts: 4
Joined: 10 Sep 2017, 21:00

Re: Unity NoesisException: ItemsPanel visual tree root must be a Panel with no children

30 Mar 2018, 05:30

Sorry for late answer but here is my xaml file for window component
<UserControl x:Class="Game.Window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    FontFamily="Fonts/#Roboto"
    
             Visibility="{Binding _IsVisible}">
  <UserControl.Style>
    <Style TargetType="{x:Type UserControl}">
      <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsVisible}"
             Value="True">
          <DataTrigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation Storyboard.TargetProperty="Opacity"
                         From="0.05" To="1.0"
                         Duration="0:0:0.5"
                         AutoReverse="False"/>
              </Storyboard>
            </BeginStoryboard>
          </DataTrigger.EnterActions>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </UserControl.Style>
  <UserControl.Resources>
    <ResourceDictionary>
      <Storyboard x:Key="ControlStoryboardRes" >
        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                 From="1.0" To="0.05"
                 Duration="0:0:0.5"
                 AutoReverse="False"/>
      </Storyboard>
      <Storyboard x:Key="ShowAnimation" >
        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                 From="0.05" To="1.0"
                 Duration="0:0:0.5"
                 AutoReverse="False"/>
      </Storyboard>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary
          Source="NoesisStyle.xaml">
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>

  <Grid Height="Auto" Width="Auto">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="56"/>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="56"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="56"/>
      <RowDefinition Height="{Binding Path=HeaderContent.Height, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"/>
      <RowDefinition Height="*"/>
      <RowDefinition Height="56"/>
    </Grid.RowDefinitions>
    <Rectangle Grid.Column="0" Grid.Row="0" Fill="{StaticResource ImageWindowBackground1}"/>
    <Rectangle Grid.Column="1" Grid.Row="0" Fill="{StaticResource ImageWindowBackground2}"/>
    <Rectangle Grid.Column="2" Grid.Row="0" Fill="{StaticResource ImageWindowBackground3}"/>

    <Rectangle Grid.Column="0" Grid.Row="1" Fill="{StaticResource ImageWindowBackground4}"/>
    <Rectangle Grid.Column="1" Grid.Row="1" Fill="{StaticResource ImageWindowBackground5}"/>
    <Rectangle Grid.Column="2" Grid.Row="1" Fill="{StaticResource ImageWindowBackground6}"/>

    <Rectangle Grid.Column="0" Grid.Row="2" Fill="{StaticResource ImageWindowBackground4}"/>
    <Rectangle Grid.Column="1" Grid.Row="2" Fill="{StaticResource ImageWindowBackground5}"/>
    <Rectangle Grid.Column="2" Grid.Row="2" Fill="{StaticResource ImageWindowBackground6}"/>

    <Rectangle Grid.Column="0" Grid.Row="3" Fill="{StaticResource ImageWindowBackground7}"/>
    <Rectangle Grid.Column="1" Grid.Row="3" Fill="{StaticResource ImageWindowBackground8}"/>
    <Rectangle Grid.Column="2" Grid.Row="3" Fill="{StaticResource ImageWindowBackground9}"/>
    <Grid Grid.ColumnSpan="3" Grid.Row="1" Margin="20,-36,20,0" Height="Auto" Width="Auto">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="24"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="8"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="{Binding Path=HeaderContent.Height, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"/>
        <RowDefinition Height="4"/>
      </Grid.RowDefinitions>
      <Rectangle Grid.Column="0" Grid.Row="0" Fill="{StaticResource ImageWindowHeader1}"/>
      <Rectangle Grid.Column="1" Grid.Row="0" Fill="{StaticResource ImageWindowHeader2}"/>
      <Rectangle Grid.Column="2" Grid.Row="0" Fill="{StaticResource ImageWindowHeader3}"/>

      <Rectangle Grid.Column="0" Grid.Row="1" Fill="{StaticResource ImageWindowHeader4}"/>
      <Rectangle Grid.Column="1" Grid.Row="1" Fill="{StaticResource ImageWindowHeader5}"/>
      <Rectangle Grid.Column="2" Grid.Row="1" Fill="{StaticResource ImageWindowHeader6}"/>

      <Rectangle Grid.Column="0" Grid.Row="2" Fill="{StaticResource ImageWindowHeader7}"/>
      <Rectangle Grid.Column="1" Grid.Row="2" Fill="{StaticResource ImageWindowHeader8}"/>
      <Rectangle Grid.Column="2" Grid.Row="2" Fill="{StaticResource ImageWindowHeader9}"/>

      <ContentPresenter Grid.Column="1" Grid.Row="1" Content="{Binding Path=HeaderContent, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"/>
      <Button Name="CloseButton" Height="26" Width="26" Margin="0,-20,0,0" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1">
        <Button.Template>
          <ControlTemplate>
            <Image   Source="../../../Game/Resources/UI/Textures/Button/Tiny Buttons/tinyButton_DeclineNoesis.png"  Stretch="Fill" StretchDirection="DownOnly" />
          </ControlTemplate>
        </Button.Template>
      </Button>
    </Grid>
    <ContentPresenter Grid.Column="1" Grid.Row="2" Content="{Binding Path=WindowContent, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" Margin="0,56,0,0" />
    
  </Grid>
</UserControl>
The styles I use is mainly NoesisStyle with changed most controls from standard ones to 9-sliced images, so it shouldn't be a problem here.

Alos the cs file behind window
using Noesis;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Events;

namespace Game
{
    public class Window : UserControl, INotifyPropertyChanged
    {
        private Visibility isVisible;
        private DoubleAnimation HideStoryboard;
        private Storyboard HideStoryboardRes;
        private Button CloseButton;

        public Visibility _IsVisible
        {
            get { return isVisible; }
            set { isVisible = value; Changed("_IsVisible");
                if ((Visibility)value == Visibility.Visible)
                {
                    DisableMainView = false;
                }
                else
                {
                    DisableMainView = true;
                }
            }
        }

        public static readonly DependencyProperty DisableMainViewProperty = DependencyProperty.Register("DisableMainView", typeof(object), typeof(Window), new FrameworkPropertyMetadata(string.Empty));

        public object DisableMainView
        {
            get { return GetValue(DisableMainViewProperty); }
            set { SetValue(DisableMainViewProperty, value); Changed("DisableMainView"); }
        }

        public static readonly DependencyProperty HeaderContentProperty = DependencyProperty.Register("HeaderContent", typeof(object), typeof(Window), new FrameworkPropertyMetadata(string.Empty));

        public object HeaderContent
        {
            get { return GetValue(HeaderContentProperty); }
            set { SetValue(HeaderContentProperty, value); }
        }

        public static readonly DependencyProperty WindowContentProperty = DependencyProperty.Register("WindowContent", typeof(object), typeof(Window), new FrameworkPropertyMetadata(string.Empty));

        public object WindowContent
        {
            get { return GetValue(WindowContentProperty); }
            set { SetValue(WindowContentProperty, value); }
        }

        public Window()
        {
            this.InitializeComponent();
            DataContext = this;
        }

        public void Show()
        {
            this._IsVisible = Visibility.Visible;
        }

        public void Hide()
        {

            //var storyboard = (Storyboard)FindName("ControlStoryboard");
            HideStoryboardRes.Begin();
        }


        public void HideMessageBoxAnimation_Completed(object sender, EventArgs e)
        {
            if (this._IsVisible == Visibility.Visible)
            {
                this._IsVisible = Visibility.Collapsed;
            }

        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void Changed(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "Assets/Game/Scripts/UI/Window.xaml");
            this._IsVisible = Visibility.Collapsed;
            this.HideStoryboardRes = (Storyboard)FindResource("ControlStoryboardRes");
            this.HideStoryboardRes.Completed += HideMessageBoxAnimation_Completed;
            Storyboard.SetTarget(this.HideStoryboardRes, this);
            this.CloseButton = (Button)FindName("CloseButton");
            CloseButton.Click += CloseButton_Click;
            //this.HideStoryboard = (DoubleAnimation)FindName("HideAnimation");
            //this.HideStoryboard.Completed += HideMessageBoxAnimation_Completed;
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            Hide();
        }
    }

}
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Unity NoesisException: ItemsPanel visual tree root must be a Panel with no children

02 Apr 2018, 15:41

I was able to reproduce the error message. It is related to ItemsPanelTemplate being applied before its VisualTree has been set during parsing.
It is a bug I need to analyze carefully, so could you please report it in our bugtracker.

Meanwhile it can be workaround by not calling Storyboard.SetTarget(this.HideStoryboardRes, this) on Game.Window's InitializeComponent. Instead you can use TargetName like this:
<UserControl x:Class="Game.Window" x:Name="GameWindowControl"...>
  ...
  <UserControl.Resources>
    <ResourceDictionary>
      <Storyboard x:Key="ControlStoryboardRes" >
        <DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="GameWindowControl"...>

Who is online

Users browsing this forum: No registered users and 0 guests