silverlight 中的手风琴问题

发布于 2024-10-12 13:56:11 字数 753 浏览 6 评论 0原文

我有一个循环的字符串列表,然后将它们添加到手风琴中。添加完所有内容后,我希望扩展最后一个项目。代码如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘦怹 2024-10-19 13:56:11

这对我来说效果很好,使用“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?

淡淡绿茶香 2024-10-19 13:56:11

我设法解决了这个问题。我认为问题出在循环中的某个地方,并且可能特定于我的代码。我所做的是将:

if (i == ivDialogList.Count - 1)
            ai.IsSelected = true;

循环中的部分移出,因此它将在循环完成后设置,如下所示:

((AccordionItem)content.Items[ivDialogList.Count - 1]).IsSelected = true;

这使它像魅力一样工作。

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:

if (i == ivDialogList.Count - 1)
            ai.IsSelected = true;

part in the loop out, so it would be set after the loop is done, like this:

((AccordionItem)content.Items[ivDialogList.Count - 1]).IsSelected = true;

And that made it work like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文