如何在wpf中的datagrid中动态添加按钮? [英] How to add button dynamically in datagrid in wpf?

查看:526
本文介绍了如何在wpf中的datagrid中动态添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPF中做一些事情。我有一个datagrid,我绑定一些值。我需要的是,每当我第二次调用该页面时,我需要在datagrid中的所有列的所有单元格中插入一个按钮(除了第一列中与某个值绑定的单元格之外)。我怎样才能做到这一点?请帮助。

解决方案

您可以添加折叠(隐藏的按钮,不占用空间)按钮到单元格,并使它们需要时可见



此行为也可以在可见性属性上使用IValueConverter绑定到某些条件。



更新tx对于我的评论,我知道有一个内置的转换器,所以这里的交易:


  1. 你添加一个这个转换器到您的窗口资源




 < Window.Resources> 
< BooleanToVisibilityConverter x:Key =myConverter/>
< /Windos.Resources>





  1. 你在你的按钮中使用它




 < Button Visibility = {Binding Path = myCondtion,Converter = {StaticResource myConverter}}/> 


其中myContition是您必须在类中创建的属性。当您希望按钮显示时,此属性的值应为true,或当您希望隐藏时为false。


I am trying to do something in WPF. I have a datagrid that I am binding with some values. What I need is that whenever I call that page the second time, I need to insert a button to all the cells of all the columns in the datagrid(except for the cells in the first column which are bound to some value). How can I do that? Please help.

解决方案

You could add collapsed (hidden buttons that don't take up space) buttons to the cells and make them visible when needed.

This behaviour also can be bind to some condition with an IValueConverter on the visibility-property.

UPDATE tx to the comment I know there is a build in converter, so here's the deal :

  1. you add a this converter to your window resources

 <Window.Resources>
    <BooleanToVisibilityConverter x:Key="myConverter"/>
  </Windos.Resources>

  1. you use it in your button

<Button   Visibility="{Binding Path=myCondtion,Converter={StaticResource myConverter}}"/>

where myContition is a property you have to create in your class. The value of this property should be true when you want your button to show , or false when you want it to be hidden..

这篇关于如何在wpf中的datagrid中动态添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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