【发布时间】:2014-06-20 15:01:28
【问题描述】:
我正在编写一个 Windows Phone 8 应用程序。我有一个与类绑定的 ListBox,它包含 XML 数据。在我的班级中有一个名为Favorite 的字段,如果Favorite 等于0,则应取消选中CheckBox,如果等于1,则应选中CheckBox。
有关更多信息,请参阅下面的代码:
<ListBox x:Name="listBox1" Width="429" Height="621" HorizontalAlignment="Left"
Margin="21,43,0,59" VerticalAlignment="Top" ItemsSource="{Binding}"
SelectedItem="{Binding}" SelectionMode="Extended">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Width="440">
<TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="Black" FontSize="22" Height="30" TextAlignment="Left" Width="Auto" FontWeight="SemiBold"/>
<TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="Black" FontSize="22" Margin="5" Height="30" TextAlignment="Left" Width="Auto" FontWeight="SemiBold"/>
<TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="Black" FontSize="22" Margin="5" Height="30" TextAlignment="Left" Width="Auto" FontWeight="SemiBold"/>
<StackPanel>
<CheckBox x:Name="CheckBox1" IsChecked="False" Height="72" Foreground="Black" Margin="358,-110,22,0" BorderBrush="Black" Loaded="CheckBox1_Loaded" Checked="CheckBox1_Checked" Unchecked="CheckBox1_Unchecked" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这是我的代码隐藏文件:
XDocument doc = XDocument.Parse(e.Result);
List<CUST_CONT> customers = new List<CUST_CONT>();
customers = (from query in doc.Descendants("row")
select new CUST_CONT
{
Id = query.Element("Id").Value,
Name = query.Element("Name").Value,
Address = query.Element("Address").Value,
Favourite = (query.Element("Favourite").Value)
}).ToList();
listBox1.DataContext = customers;
【问题讨论】:
标签: c# windows-phone-8 checkbox