Silverlight 工具包 Accordion ScrollViewer

发布于 2025-01-02 02:58:16 字数 1274 浏览 6 评论 0原文

我正在用数据库中的项目填充我的手风琴。我还将我的手风琴包装在 ScrollViewer 中:

<ScrollViewer Name="LayoutScrollViewer">
    <toolkit:Accordion Name="ItemsAccordion" ItemTemplate="{StaticResource AccordionHeaderTemplate}" ContentTemplate="{StaticResource AccordionContentTemplate}"></toolkit:Accordion>
</ScrollViewer>

但是,我找不到一种方法来最初将 ScrollViewer 的 VerticalOffset 显示为 0。每当我的数据库内容加载完成时,它就会继续滚动到底部。我在代码隐藏中尝试过:

void CatalogItem_Loaded(object sender, RoutedEventArgs e)
{
    WebServiceClient client = new WebServiceClient();
    client.GetCatalogItemsAsync(countID);
    client.GetCatalogItemsCompleted += new EventHandler<GetCatalogItemsCompletedEventArgs>(client_GetCatalogItemsCompleted);
}

void client_GetCatalogItemsCompleted(object sender, GetCatalogItemsCompletedEventArgs e)
{
    ItemsAccordion.ItemsSource = e.Result;

    UpdateScrollViewer();
}

 private void UpdateScrollViewer()
 {
     LayoutScrollViewer.ScrollToVerticalOffset(0);
 }

但这不起作用。我也尝试过,在 UpdateScrollViewer() 中执行以下操作:

LayoutScrollViewer.IsHitTestVisible = false;
LayoutScrollViewer.IsHitTestVisible = true;

这也不起作用。如果我将其保留为 IsHitTestVisible= false,那么它会按我想要的方式工作;但我也希望用户与手风琴进行交互,所以这不是一个永久的解决方案。

I am populating my Accordion with items from my database. I have also wrapped my Accordion in a ScrollViewer:

<ScrollViewer Name="LayoutScrollViewer">
    <toolkit:Accordion Name="ItemsAccordion" ItemTemplate="{StaticResource AccordionHeaderTemplate}" ContentTemplate="{StaticResource AccordionContentTemplate}"></toolkit:Accordion>
</ScrollViewer>

However, I cannot find a way to initially show the VerticalOffset of the ScrollViewer to 0. It keeps on scrolling to the bottom whenever my database content is finished loading. I have tried in the codebehind:

void CatalogItem_Loaded(object sender, RoutedEventArgs e)
{
    WebServiceClient client = new WebServiceClient();
    client.GetCatalogItemsAsync(countID);
    client.GetCatalogItemsCompleted += new EventHandler<GetCatalogItemsCompletedEventArgs>(client_GetCatalogItemsCompleted);
}

void client_GetCatalogItemsCompleted(object sender, GetCatalogItemsCompletedEventArgs e)
{
    ItemsAccordion.ItemsSource = e.Result;

    UpdateScrollViewer();
}

 private void UpdateScrollViewer()
 {
     LayoutScrollViewer.ScrollToVerticalOffset(0);
 }

This doesn't work, though. I have also tried, in UpdateScrollViewer() to do:

LayoutScrollViewer.IsHitTestVisible = false;
LayoutScrollViewer.IsHitTestVisible = true;

which doesn't work either. If I leave it as IsHitTestVisible= false, then it works as I would like; but I also want user interaction with the Accordion, so this isn't a permanent solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

满栀 2025-01-09 02:58:16

我讨厌这样做,但你有以下几点:

void client_GetCatalogItemsCompleted(object sender, GetCatalogItemsCompletedEventArgs e)
{
    ItemsAccordion.ItemsSource = e.Result;
    UpdateLayout();
    UpdateScrollViewer();
}

I hate to do this but thy the following:

void client_GetCatalogItemsCompleted(object sender, GetCatalogItemsCompletedEventArgs e)
{
    ItemsAccordion.ItemsSource = e.Result;
    UpdateLayout();
    UpdateScrollViewer();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文