Unity NoesisException: ItemsPanel visual tree root must be a Panel with no children
Posted: 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.
Code: Select all
<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>