R – How to add button dynamically in datagrid in wpf

buttondatagridwpf

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.

Best Answer

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..