在 windows Phone 8 c# 中不止一次设置了属性“visualTree" [英] The property 'visualTree' is set more than once in windows Phone 8 c#
本文介绍了在 windows Phone 8 c# 中不止一次设置了属性“visualTree"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 Windows Phone 应用程序中,我想获取所有带有复选框的联系人并显示在列表框中
In my windows phone application, I want to get all contacts with checkbox and show in list box
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,10">
<TextBlock x:Name="ContactResultsLabel" Text="results are loading..." Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap"></TextBlock>
<ListBox x:Name="ContactResultsData" ItemsSource="{Binding listOfContacts}" Height="293" Margin="24,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Name="contactChk" IsChecked="true" Foreground="Black" Background="Black" BorderBrush="Black"></CheckBox>
<TextBlock x:Name="ContactResultsName" Text="{Binding Name}" FontSize="50"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
但是当我在列表框的 DataTemplate
中添加 Checkbox
和 Textblock
时,它会出现以下错误:
But when I add Checkbox
and Textblock
in the DataTemplate
of the listbox it gets me error below:
多次设置属性 'visualTree'
我不明白为什么它会给出,请建议我,等待您的答复.谢谢.
I don't understand why it gives, Kindly suggest me, waiting for your reply. Thanks.
推荐答案
DataTemplate中只能添加一个Element根,代码可以这样改:
You can add only one Element root in DataTemplate, code can change like this:
<DataTemplate>
<Grid>
<CheckBox Name="contactChk" IsChecked="true" Foreground="Black" Background="Black" BorderBrush="Black"></CheckBox>
<TextBlock x:Name="ContactResultsName" Text="{Binding Name}" FontSize="50"></TextBlock>
</Grid>
</DataTemplate>
这篇关于在 windows Phone 8 c# 中不止一次设置了属性“visualTree"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文