如何动态地添加按钮,在数据网格的WPF? [英] How to add button dynamically in datagrid in wpf?

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

问题描述

我试图做WPF的东西。我有一个DataGrid,我与一些值绑定。我需要的是,每当我调用页面的第二次,我需要插入一个按钮的DataGrid(除了在第一列的单元格被绑定到某一值)中的所有列的所有单元格。我该怎么办呢?请帮助。


解决方案

您可以添加折叠(隐藏按钮,不占用空间)按钮细胞,使其可见在需要的时候。

此行​​为也可以被绑定到某个条件与能见度属性的的IValueConverter。

更新TX到我知道有在转炉构建的评论,所以这里的交易:


  1. 您添加此转换器到你的窗口资源


 < Window.Resources>
    < BooleanToVisibilityConverter X:键=myConverter/>
  < /Windos.Resources>



  1. 您使用它在你的按钮


 <按钮能见度={绑定路径= myCondtion,转换器= {StaticResource的myConverter}}/>


在这里myContition是你必须在你的类来创建一个属性。当你想你的按钮显示该属性的值应该是真的,还是假的,当你希望它被隐藏..

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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