wpf DataGridTextColumn重构

编程入门 行业动态 更新时间:2024-10-23 10:27:25
本文介绍了wpf DataGridTextColumn重构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在WPF应用程序中使用了一个DataGrid,该应用程序具有几个(一般为一周的一周)列,这些列仅在其数据索引中有所不同。 xaml的样本如下:

I am using a DataGrid in a WPF app that has several (literally one for each day of the week) columns which differ only in their data index. A sample of the xaml is below.

如何将其重新导入更多的DRY?

How can I refactor this into something more DRY?

干杯, Berryl

Cheers, Berryl

样品XAML(七列中的两列):

SAMPLE XAML (two of seven columns):

<dg:DataGridTextColumn Header="{Binding Source={StaticResource spy}, Path=DataContext[0].EventDate, Converter={StaticResource dateConv}}" CellStyle="{StaticResource DataEntryCellStyle}" Width="60" CanUserResize="False" Binding="{Binding Allocations[0].Amount, Converter={StaticResource amtConv}}" /> <dg:DataGridTextColumn Header="{Binding Source={StaticResource spy}, Path=DataContext[1].EventDate, Converter={StaticResource dateConv}}" CellStyle="{StaticResource DataEntryCellStyle}" Width="60" CanUserResize="False" Binding="{Binding Allocations[1].Amount, Converter={StaticResource amtConv}}" />

== EDITED ADD'L INFO @ JALFP ===

== EDITED ADD'L INFO @ JALFP ===

编译器抱怨目标类型在构建时不是框架元素

Compiler complains that the target type is not a framework element when building

<Style x:Key="dayOfWeekColumn" TargetType="dg:DataGridTextColumn" > <Setter Property="CanUserResize" Value="False"/> <Setter Property="CanUserSort" Value="False"/> <Setter Property="Width" Value="60" /> <Setter Property="CellStyle" Value="{StaticResource dataEntryGridCellStyle}" /> </Style>

我也看不到任何类似ColumnStyle的东西。在DataGridTextColumn的xaml中,我将设置什么属性?

I don't see anything that looks like a ColumnStyle either. What property would I set this style to in the xaml for the DataGridTextColumn?

推荐答案

也许你可以创建自己的类继承自DataGridTextColumn并添加一个新的DependencyProperty DayIndex(从0到6)。然后在这个课程中,你可以在XAML中进行初始化...

Maybe you can create your own class which inherits from DataGridTextColumn and add a new DependencyProperty DayIndex (from 0 to 6). Then in this class you could to the initialization you're doing in the XAML...

但我不知道这将是一个更好和更可维护的解决方案...

But I'm not sure it will be a really better and more maintainable solution...

更多推荐

wpf DataGridTextColumn重构

本文发布于:2023-11-03 12:44:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555166.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重构   wpf   DataGridTextColumn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!