繁体   English   中英

根据列值将分配的功能和文本更改为WPF Datagrid中的按钮

[英]Change the assigned function and text to a button in a WPF Datagrid depending on column value

我在列中有此按钮:

<DataGridTemplateColumn>
       <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                     <Button Click="UpdateTopic">Update</Button>
              </DataTemplate>
       </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

但是现在我需要根据其中一列中的值更改其中的文本和应用于它的函数。 我该如何实现?

在您的代码后面创建一个属性或查看模型,并将其绑定到Button.Content属性:

<Button Click="UpdateTopic" Content={Binding ButtonText}" />

假设随着列值的更改,您可以访问绑定到DataGrid数据对象,请在代码中编辑与Button.Click事件链接的方法,如下所示:

public void UpdateTopic()
{
    if (columnValue == "Something") DoSomething();
    else if (columnValue == "SomethingElse") DoSomethingElse();
    else if (columnValue == "AnotherThing") DoAnotherThing();
}

这样,您可以使一键式处理程序执行取决于列的当前值的各种任务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM