如何隐藏数据网格详细信息行

发布于 2024-10-19 16:15:21 字数 274 浏览 1 评论 0原文

我有一个数据网格,其 RowDetialsVisibilityMode 设置为 VisibleWhenSelected,并相应设置了 RowDetailsTemplate。当用户选择一行时,会显示详细信息,这与描述的完全相同。然而,在查看详细信息后,用户希望再次隐藏该行详细信息而不显示另一行的详细信息。如何最好地实现这一点。

更新:正如评论中提到的,最好的选择可能是详细信息行中的一个按钮来隐藏该行,但我想知道绑定会是什么样子?

I have a datagrid with the RowDetialsVisibilityMode set to VisibleWhenSelected, and the RowDetailsTemplate set accordingly. When the user selects a row, the detail shows, which is exactly as described. However after reviewing the details, the user would like to hide the row detail again without showing the details of another row. How is this best accomplished.

Update: As mentioned in the comments, the likely the best option would be a button in the details row to hide the row, but then I wonder what would the binding look like?

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

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

发布评论

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

评论(1

轮廓§ 2024-10-26 16:15:21

由于此功能是基于演示的,因此我会为按钮创建一个折叠行的行为,

public class CollapseRowAction : TriggerAction<ButtonBase>
{
    public CollapseRowAction() {}
    protected override void Invoke(object o)
    {
        var dg = FindVisualParent<DataGrid>(this.AssociatedObject);
        if (dg != null)
            dg.SelectedIndex = -1;

    }

    private static T FindVisualParent<T>(DependencyObject child) where T : DependencyObject
    {      

        DependencyObject parentObject = VisualTreeHelper.GetParent(child);   
        if (parentObject == null) return null; 

        T parent = parentObject as T;
        if (parent != null) 
        { 
            return parent; 
        }
        else
        {
            return FindVisualParent<T>(parentObject);
        }
    }
}

并且在 XAML 中:

<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <!--... However row details are presented ...-->
        <Button Margin="10" Content="Collapse">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <myTriggers:CollapseRowAction/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </StackPanel>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>

Since this functionality is presentation-based, I'd create a behavior for the button that would collapse the row

public class CollapseRowAction : TriggerAction<ButtonBase>
{
    public CollapseRowAction() {}
    protected override void Invoke(object o)
    {
        var dg = FindVisualParent<DataGrid>(this.AssociatedObject);
        if (dg != null)
            dg.SelectedIndex = -1;

    }

    private static T FindVisualParent<T>(DependencyObject child) where T : DependencyObject
    {      

        DependencyObject parentObject = VisualTreeHelper.GetParent(child);   
        if (parentObject == null) return null; 

        T parent = parentObject as T;
        if (parent != null) 
        { 
            return parent; 
        }
        else
        {
            return FindVisualParent<T>(parentObject);
        }
    }
}

And in XAML:

<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <!--... However row details are presented ...-->
        <Button Margin="10" Content="Collapse">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <myTriggers:CollapseRowAction/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </StackPanel>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文