WPF DataGrid 自动生成列,更改标题名称

发布于 2024-09-27 08:14:36 字数 96 浏览 0 评论 0原文

我记得在 Silverlight 中,当在数据网格上自动生成列时,可以将属性放置在模型中的给定属性上以作为备用显示名称。这在 WPF 中可能吗?我不想使用事件处理程序来更改名称。

I recall in Silverlight the ability to place an Attribute on a given property in the Model for an alternate display name when auto generating columns on a data grid. Is this possible in WPF? I don't want to use the event handler to change the names.

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

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

发布评论

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

评论(2

余生再见 2024-10-04 08:14:36

找到它...这是我引用的 DisplayAttribute,但是这在 WPF 中无效,仅在 SL 中有效。对于 WPF,可以这样做...将所有内容保留在 XAML 中...

    <dg:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding DatabaseConnections, Mode=Default}">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Header="Display" Binding="{Binding DisplayName}"></dg:DataGridTextColumn>
        </dg:DataGrid.Columns>
    </dg:DataGrid>

...这允许您更改 DisplayName 属性以在 的标题中显示为“Display” >数据网格

Found it...here is what I was referencing DisplayAttribute, however that does not appear valid in WPF, only SL. For WPF it can be done like this...keeping everything in XAML...

    <dg:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding DatabaseConnections, Mode=Default}">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Header="Display" Binding="{Binding DisplayName}"></dg:DataGridTextColumn>
        </dg:DataGrid.Columns>
    </dg:DataGrid>

...this allows you to change the DisplayName property to get displayed as "Display" in the header of the DataGrid.

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