Silverlight 中具有模板化 RowHeader 和 ColumnHeader 的 DataGrid

发布于 2024-12-28 07:52:58 字数 205 浏览 5 评论 0原文

如何使用模板化的 RowHeader、ColumnHeader 和 Cells 创建网格?

ViewModel 可以具有用于 RowHeader 项显示的对象列表、用于 ColumnHeader 项显示的对象列表。基本上可以将其视为矩阵显示器。

可能需要编写一个 ControlTemplate,但没有想法。关于此功能的文档不多。

有什么想法吗?

How to create a grid with a templated RowHeader, ColumnHeader, and Cells?

The ViewModel can have a list of objects for RowHeader item display, a list of objects for ColumnHeader item display. Basically think of it like a matrix display.

Probably a ControlTemplate needs to be written, but running out of ideas. There's not much of a documentation on this functionality.

Any Ideas?

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

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

发布评论

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

评论(1

离不开的别离 2025-01-04 07:52:58

您可以为 DataGridColumnHeader 或 DataGridRowHeader 创建样式,并将 ContentTemplate 设置为允许绑定 Header 属性的 DataTemplate。为此,您需要一个启用绑定的 IValueConverter。

标头位于 Controls.Primitives 命名空间中:

xmlns:dp="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

样式:

        <Style TargetType="dp:DataGridColumnHeader" >
            <Setter Property="ContentTemplate" >
                <Setter.Value>
                    <DataTemplate>
                        <ContentPresenter Content="{Binding Converter={StaticResource vcBC}}"  />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

转换器:

public class BindingConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value.GetType().Name == "Binding")
        {
            ContentControl cc = new ContentControl();
            cc.SetBinding(ContentControl.ContentProperty, value as Binding);
            return cc;
        }
        else return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

转换器实例:

<yourassembly:BindingConverter x:Key="vcBC"/>

You can create a style for a DataGridColumnHeader or a DataGridRowHeader and set the ContentTemplate to a DataTemplate which allows the Header property to be bound. For this you need an IValueConverter which enables the binding.

The headers are in the Controls.Primitives namespace:

xmlns:dp="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

Style:

        <Style TargetType="dp:DataGridColumnHeader" >
            <Setter Property="ContentTemplate" >
                <Setter.Value>
                    <DataTemplate>
                        <ContentPresenter Content="{Binding Converter={StaticResource vcBC}}"  />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Converter:

public class BindingConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value.GetType().Name == "Binding")
        {
            ContentControl cc = new ContentControl();
            cc.SetBinding(ContentControl.ContentProperty, value as Binding);
            return cc;
        }
        else return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

Converter instance:

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