我有一个带有ItemTemplate的ListBox,里面有一个复选框。现在,我想绑定我的列表,以便每个复选框从数组中获取其内容。听起来很简单,但并不管用。
这就是我所拥有的:
<ListBox SelectionMode="Multiple" x:Name="ListAvailableHours" SelectedIndex="0" Margin="0,9.5,0,0" Height="Auto">
   <ListBox.ItemTemplate>
       <DataTemplate>
           <CheckBox Content="{Binding}" />
       </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>和我背后的代码
List<string> AvailableHours = new List<string>();
DateTime now = DateTime.Now;
AvailableHours.Add(now.ToString());
AvailableHours.Add(now.AddHours(1).ToString());
AvailableHours.Add(now.AddHours(2).ToString());
AvailableHours.Add(now.AddHours(3).ToString());
AvailableHours.Add(now.AddHours(4).ToString());
ListAvailableHours.ItemsSource = AvailableHours;当我尝试打开这个页面时,我得到了以下异常:
"An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occured     in WindowsPhone.exe but was not handled in user code.
WinRT Information: E_UNKOWN_ERROR [Line:44 Position:44]
Additional Information: The text associated with this error code could not be found."第44行,位置44指向
</ListBox.ItemTemplate>所以我假设绑定的某些东西是关闭的?
发布于 2015-05-21 01:14:40
我觉得自己太傻了。我之前对一些项目进行了硬编码,并设置了SelectedIndex=0使其处于选中状态。现在我添加了一个DataTemplate,这显然是错误的:)
删除了SelectedIndex,现在它可以工作了,谢谢。
https://stackoverflow.com/questions/30355834
复制相似问题