WPF DataGrid按钮列禁用 [英] WPF DataGrid Button Column Disable

查看:1132
本文介绍了WPF DataGrid按钮列禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在DataGridTemplateColumn中禁用按钮吗?我有一个DataGridTemplate,如下所示:

Is it possible to disable a button in a DataGridTemplateColumn? I have a DataGridTemplate as follows:

<toolkit:DataGridTemplateColumn Header="Timer" Width="50">
                    <toolkit:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Start" Click="Button_Click" CommandParameter="{Binding}" />
                        </DataTemplate>
                    </toolkit:DataGridTemplateColumn.CellTemplate>
                </toolkit:DataGridTemplateColumn>

按钮的目的是启动记录到与该行相关联的对象的定时器。我的计时器代码工作正常,但我也想禁用其他行的按钮,以便您只能运行一个计时器。

The purpose of the Button is to start a timer recorded to the object associated with that row. My timer code works fine but I would also like to disable the buttons of every other row so that you can only have one timer running.

我使用

WorkItemGrid.Columns [WorkItemGrid.Columns.Count - 1] .GetCellContent(item).IsEnabled = false

禁用它,所有按钮正确显示禁用,但如果您点击按钮两次,它将重新启用,并允许您第三次单击它并触发Click事件。有可能实际上禁用按钮吗?

to disable it and all the buttons correctly appear disabled but if you click on the button twice it will reenable and allow you to click on it a third time and trigger the Click event. Is it possible to actually disable the button?

推荐答案

我将有一个对象,Datagrid必须公开一个IsEnabled布尔属性我可以绑定按钮。每当调用处理程序时,只需从原始集合获取另一个对象,并将其属性更改为false。这将自动禁用其他按钮。

I would have the object the Datagrid is bound to expose a "IsEnabled" boolean property I can bind the button to. Whenever the handler is called, simply get the other object from your original collection and have them change their property to false. This will automatically disable the other buttons.

如果您不能控制定时器类,则可以在将数据绑定到网格之前将其包装到自己的类中收集您的对象。

If your are not in control of the "timer" class, you can wrap it in your own class before databinding the grid to the collection of your objects.

这篇关于WPF DataGrid按钮列禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆