如何隐藏UniformGrid Control的第一行?

时间:2010-11-05 12:50:21

标签: wpf uniformgrid

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

我该如何实现?

1 个答案:

答案 0 :(得分:1)

我从来没有使用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;
    }
}