'VisualTree' 设置不止一次 [英] 'VisualTree' is set more than once

查看:57
本文介绍了'VisualTree' 设置不止一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此 xaml 文件中的错误:

I keep getting an error in this xaml file:

属性 'VisualTree' 设置了不止一次.

The property 'VisualTree' is set more than once.

<ListBox x:Name="lstHistory" HorizontalAlignment="Left" Margin="12,284,0,90" Width="460"
                 ItemsSource="{Binding
                                Source={StaticResource SongCollection},
                                Path=DataCollection}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="5" VerticalAlignment="top" Source="{Binding Path=Image}" />
                    </StackPanel>
                    <TextBlock Margin="8" Width="250"
                  TextWrapping="Wrap"
                  VerticalAlignment="Top"
                  HorizontalAlignment="Left"
                  Text="{Binding Path=Name}" />
                    <TextBlock Width="100"
                  Margin="8,0,8,8"
                  VerticalAlignment="Top"
                  HorizontalAlignment="Left"
                  Text="{Binding Path=Artist}" />
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>

谁能帮忙?

推荐答案

DataTemplate 只能有 1 个子项.你有 2 个(堆栈面板和文本块).把它们包在一个容器里,一切都会好的

DataTemplate can only have 1 child. you've got 2 (stackpanel and textblock). wrap those in single container and all will be well

这篇关于'VisualTree' 设置不止一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆