【问题标题】:'VisualTree' is set more than once'VisualTree' 设置不止一次
【发布时间】:2012-05-16 15:10:53
【问题描述】:

我在这个 xaml 文件中不断收到错误:

属性“VisualTree”被设置了多次。

<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>

谁能帮忙?

【问题讨论】:

    标签: windows-phone-7 xaml


    【解决方案1】:

    DataTemplate 只能有 1 个孩子。你有 2 个(堆栈面板和文本块)。将它们包装在一个容器中,一切都会好起来的

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      相关资源
      最近更新 更多