如何隐藏 UniformGrid 控件的第一行?

发布于 2024-09-30 10:54:25 字数 65 浏览 1 评论 0原文

UniformGrid 已加载数据,我想隐藏第一行吗?

我怎样才能实现它?

UnifomGrid has loaded Data, I want to Hide the first row?

How can I implement that?

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

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

发布评论

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

评论(1

把时间冻结 2024-10-07 10:54:25

我从未使用过 UniformGrid,因此可能有更好的解决方案,但据我所知,UniformGrid 除了有多少行之外不包含太多信息和它目前拥有的列,因此这是我能想到的唯一解决方案。

private List<UIElement> GetElementsAtRow(int rowNumber)
{
    List<UIElement> elementsAtRow = new List<UIElement>();
    for (int i = 0; i < uniformGrid.Columns; i++)
    {
        if (i < uniformGrid.Children.Count)
        {
            elementsAtRow.Add(uniformGrid.Children[i] as UIElement);
        }
    }
    return elementsAtRow;
}
private void HideFirstRow()
{
    List<UIElement> elementsAtRow = GetElementsAtRow(0);
    foreach (UIElement element in elementsAtRow)
    {
        // Or Hidden if you want row to remain but with no Visible children.
        element.Visibility = Visibility.Collapsed;
    }
}
private void ShowFirstRow()
{
    List<UIElement> elementsAtRow = GetElementsAtRow(0);
    foreach (UIElement element in elementsAtRow)
    {
        element.Visibility = Visibility.Visible;
    }
}

I've never worked with the UniformGrid so there might be a better solution for this but as far as I can tell the UniformGrid doesn't hold much information except how many rows and columns it currently have so therefore this is the only solution that I can think of.

private List<UIElement> GetElementsAtRow(int rowNumber)
{
    List<UIElement> elementsAtRow = new List<UIElement>();
    for (int i = 0; i < uniformGrid.Columns; i++)
    {
        if (i < uniformGrid.Children.Count)
        {
            elementsAtRow.Add(uniformGrid.Children[i] as UIElement);
        }
    }
    return elementsAtRow;
}
private void HideFirstRow()
{
    List<UIElement> elementsAtRow = GetElementsAtRow(0);
    foreach (UIElement element in elementsAtRow)
    {
        // Or Hidden if you want row to remain but with no Visible children.
        element.Visibility = Visibility.Collapsed;
    }
}
private void ShowFirstRow()
{
    List<UIElement> elementsAtRow = GetElementsAtRow(0);
    foreach (UIElement element in elementsAtRow)
    {
        element.Visibility = Visibility.Visible;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文