WPF 数据网格:禁用某些行中的编辑
我有一些类似绑定到 DataGrid 的订单表的东西。 我想禁用对订单日期已过期的行进行编辑(截止日期>当前日期):将它们显示为灰色并禁止进入编辑模式。
这就是我所拥有的:
<Style TargetType="{x:Type WPFToolkit:DataGridRow}">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<!-- ??? order_date > current_date -->
<!-- some other condition - already works -->
</MultiTrigger.Conditions>
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Foreground" Value="LightGray"/>
</MultiTrigger>
</Style.Triggers>
</Style>
订单日期是一个模板列,定义如下:
<WPFToolkit:DataGridTemplateColumn SortMemberPath="order_date" Header="Deadline" >
<WPFToolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=order_date,
ConverterCulture='ru-RU', StringFormat='{}{0:d}'}" />
</DataTemplate>
</WPFToolkit:DataGridTemplateColumn.CellTemplate>
<WPFToolkit:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<WPFToolkit:DatePicker SelectedDate="{Binding Path=order_date}" />
</DataTemplate>
</WPFToolkit:DataGridTemplateColumn.CellEditingTemplate>
</WPFToolkit:DataGridTemplateColumn>
有没有办法在订单日期已过期的行中禁用编辑模式?
I have something like orders table bound to a DataGrid
.
I want to disable editing on rows, where order date is expired (deadline date > current date): show them greyed and ban entering into edit mode.
Here is what I have:
<Style TargetType="{x:Type WPFToolkit:DataGridRow}">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<!-- ??? order_date > current_date -->
<!-- some other condition - already works -->
</MultiTrigger.Conditions>
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Foreground" Value="LightGray"/>
</MultiTrigger>
</Style.Triggers>
</Style>
The order date is a template column defined as follows:
<WPFToolkit:DataGridTemplateColumn SortMemberPath="order_date" Header="Deadline" >
<WPFToolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=order_date,
ConverterCulture='ru-RU', StringFormat='{}{0:d}'}" />
</DataTemplate>
</WPFToolkit:DataGridTemplateColumn.CellTemplate>
<WPFToolkit:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<WPFToolkit:DatePicker SelectedDate="{Binding Path=order_date}" />
</DataTemplate>
</WPFToolkit:DataGridTemplateColumn.CellEditingTemplate>
</WPFToolkit:DataGridTemplateColumn>
Is there a way to disable editing mode in rows where order date has expired?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以看起来一切正常,但您需要一种方法来检查触发器中的(order_date > current_date)?如果是这种情况,您可以编写一个 ValueConverter(例如 DateExpiredConverter)并检查那里的条件并返回一个布尔值。
转换器类可能看起来像这样:
然后在触发器中执行如下操作:
我尚未测试此代码,但它应该非常接近您需要的内容。
So it seems that everything works but you need a way to check (order_date > current_date) in a Trigger? If that is the case, you could write a ValueConverter like perhaps DateExpiredConverter and check the condition there and return a boolean.
The converter class might look something like this:
Then in your trigger you do something like this:
I haven't tested this code but it should be pretty close to what you need.