如何在wpf中的datagrid中动态添加按钮? [英] How to add button dynamically in datagrid in wpf?
问题描述
您可以添加折叠(隐藏的按钮,不占用空间)按钮到单元格,并使它们需要时可见
此行为也可以在可见性属性上使用IValueConverter绑定到某些条件。
更新tx对于我的评论,我知道有一个内置的转换器,所以这里的交易:
- 你添加一个这个转换器到您的窗口资源
-
< Window.Resources>
< BooleanToVisibilityConverter x:Key =myConverter/>
< /Windos.Resources>
- 你在你的按钮中使用它
< 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 :
- you add a this converter to your window resources
<Window.Resources> <BooleanToVisibilityConverter x:Key="myConverter"/> </Windos.Resources>
- 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屋!