silverlight 中的手风琴问题
我有一个循环的字符串列表,然后将它们添加到手风琴中。添加完所有内容后,我希望扩展最后一个项目。代码如下所示:
for (int i = 0; i < ivDialogList.Count; i++)
{
AccordionItem ai = new AccordionItem();
ai.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.Content = ivDialogList[i].Message;
ai.Header = ivDialogList[i].PostType + " " + ivDialogList[i].User + " " + ivDialogList[i].PostDate;
if (i == ivDialogList.Count - 1)
ai.IsSelected = true;
content.Items.Add(ai);
}
这工作正常,但是一旦我单击任何其他手风琴项目或关闭最后一个项目,我就会收到超出范围的异常。是否有人有其他方法可以做到这一点,或者知道我得到例外的原因并可以提供帮助。 谢谢
I have a list of strings that I loop throu, and then add them in a Accordion. When I've added all of them I want the last item to expand. The code looks like this:
for (int i = 0; i < ivDialogList.Count; i++)
{
AccordionItem ai = new AccordionItem();
ai.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
ai.Content = ivDialogList[i].Message;
ai.Header = ivDialogList[i].PostType + " " + ivDialogList[i].User + " " + ivDialogList[i].PostDate;
if (i == ivDialogList.Count - 1)
ai.IsSelected = true;
content.Items.Add(ai);
}
This is working fine, but as soon as I click on any of the other accordion items or close the last one, I get an out of range exception. Does any body have another way of doing this or know the reason why I get the exception and can help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我来说效果很好,使用“Lore Ipsum..”文本、工具包 Accordion 和一堆 AccordionItems - 问题一定出在您未在此处显示的某些代码中。您可以发布堆栈跟踪和 XAML 吗?
This works fine for me using "Lore Ipsum.." text, the toolkit Accordion and a bunch of AccordionItems - the problem must be in some of your code that you are not showing here. Can you post a stacktrace and the XAML?
我设法解决了这个问题。我认为问题出在循环中的某个地方,并且可能特定于我的代码。我所做的是将:
循环中的部分移出,因此它将在循环完成后设置,如下所示:
这使它像魅力一样工作。
I managed to solve the question. I think the problem was somewhere in the loop, and probably specific for my code. What I did was that I moved the:
part in the loop out, so it would be set after the loop is done, like this:
And that made it work like a charm.