gpt4 book ai didi

XAML 错误 : "The property ' VisualTree' is set more than once"

转载 作者:行者123 更新时间:2023-12-03 00:53:16 28 4
gpt4 key购买 nike

我正在尝试将两个网格放入 DataTemplate 中。

我的代码出现以下错误,如下所示。

Error: "The property 'VisualTree' is set more than once"

<DataTemplate x:Key="PareoItemTemplate">
<Grid x:Name="gridColorEjercicio" Height="100" Width="350" Background="#FFF0F0F0" Margin="-11,0,0,0">
<StackPanel Margin="0" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Margin="0,10,15,0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding letter}" FontSize="24" FontFamily="Resources/Fonts/Programa Tutorias Bold.ttf#Programa Tutorias" Foreground="Black" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="{Binding option}" FontSize="24" FontFamily="Resources/Fonts/Programa Tutorias Bold.ttf#Programa Tutorias" Width="253" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<Grid VerticalAlignment="Center" Margin="5,10,5,0" HorizontalAlignment="Center">
<Image Source="{Binding imageURI}" />
</Grid>
</StackPanel>
</Grid>
<Grid x:Name="gridPareoColorEjercicio" Height="100" Width="350" Background="#FFF0F0F0" Margin="-11,0,0,0">
<StackPanel Margin="0" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Margin="0,10,15,0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding letter}" FontSize="24" FontFamily="Resources/Fonts/Programa Tutorias Bold.ttf#Programa Tutorias" Foreground="Black" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="{Binding option}" FontSize="24" FontFamily="Resources/Fonts/Programa Tutorias Bold.ttf#Programa Tutorias" Width="253" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<Grid VerticalAlignment="Center" Margin="5,10,5,0" HorizontalAlignment="Center">
<Image Source="{Binding imageURI}" />
</Grid>
</StackPanel>
</Grid>
</DataTemplate>

最佳答案

数据模板只能有一个可视化树,但您要定义两个网格。如果您希望两个网格彼此相邻或一个在另一个网格下,请将它们包装在 StackPanel 中,并相应地设置属性 Orientation

<DataTemplate>
<StackPanel Orientation="Vertical">
<Grid>[...]</Grid>
<Grid>[...]</Grid>
</StackPanel>
</DataTemplate>

关于XAML 错误 : "The property ' VisualTree' is set more than once",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22965447/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com