I have created a xamgrid programmatically and I am binding a dynamic dataTable to it. I would like to create a column with buttons in xamgrid programmatically.
Hello Ramesh,
You may control the visibility of the buttons for example by adding a new property of type Visibility in your data model and after that binding it to the Button Visibility property.
<DataTemplate x:Key="CustomButtonTemplate">
<Button Content="{Binding RowData.CategoryID}" Visibility="{Binding RowData.Visible}" />
</DataTemplate>
I’ve attached a modified sample demonstrating this.
Hi,
I would also like to know if it is possible to display buttons only for certain rows in a unbound column and leave the others empty. For example, if the dynamically binded button content of the unbound column is empty, button shouldn't be added to the xamgrid unbound column.
Hello,
Thanks for your reply.
The binding works perfectly if the column name is explicitly specified in binding. But if I assign a variable with the dynamically generated column name, I get the following Binding error:
"System.Windows.Data Error: 40 : BindingExpression path error: 'buttonColumnName' property not found on 'object' ''UnboundColumnDataContext' (HashCode=47151178)'. BindingExpression:Path=buttonColumnName; DataItem='UnboundColumnDataContext' (HashCode=47151178); target element is 'Button' (Name='btn'); target property is 'Content' (type 'Object')"
Could you please let me know how to bind the button content with a dynamically generated column name?
You can see more about unbound columns binding here:
http://ko.infragistics.com/help/wpf/xamgrid-itemtemplate-binding
You can see more about unbound columns merging and sorting here:
http://ko.infragistics.com/help/wpf/xamgrid-merged-cells
http://ko.infragistics.com/help/wpf/xamgrid-sorting-unbound-columns
I’ve attached a sample application for your reference.
Thanks for your reply. In the sample provided, the button content remains the same for all buttons. How do I bind the button content for each of the buttons based on a certain cell value? Also is it possible to merge unbound(button) column based on row value?