I am creating Gridview with dynamic columns as below.
gridViewCol.DisplayMemberBinding = new Binding(string.Format("[{0}]", indexToUse));
I was binding the ListView Itemssource to
ObservableCollection<List<string>>
This is working fine.
Now
We have a new requirement now that on these dynamic gridviewcolumn cells, I need to displays a ToggleButton/Popup depending on the data. The popup should displays a listbox.
For this I need to use GridViewColumn CellTemplate.
But with datatemplate for CellTemplate in Xaml, how do I pass the index information(indexToUse above)?
ListView Itemssource now binds to
ObservableCollection<List<ItemRow>> instead of ObservableCollection<List<string>>
ItemRow
public class ItemRow : NotificationObject
{
private string cellItem = string.Empty;
public string CellItem
{
get { return cellItem; }
set
{
cellItem = value;
RaisePropertyChanged(() => CellItem);
}
}
private bool isMultiValued = false;
public bool IsMultiValued
{
get { return isMultiValued; }
set { isMultiValued = value; }
}
private List<string> multiValuedCellItem = new List<string>();
public List<string> MultiValuedCellItem
{
get { return multiValuedCellItem; }
set { multiValuedCellItem = value; }
}
}
I tried other alternatives to dynamically build the datatemplate like XAMLReader.Load and FrameworkElementFactory.
XAMLReader works but does not allow event handlers which is a problem.
FrameworkElementFactory does not work as required. Same is given per
http://www.ikriv.com/dev/wpf/DataTemplateCreation/[
^]
Using Relative source binding to get the column index also does not work. I cant use ElementName as columns are dynamic.
I tried using the similar solution as given here, but did not work
http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/[
^]
Could anyone please suggest any other alternative solutions or suggestions on how to use Celltemplate with dynamic gridview columns.