Hi,
I'm really pulling my hair with this one, so any help I can get would be greatly appreciated!
Here is the thing... I am using MVVM and I need to create a grid with (to start with) one row and a variable number of columns. The name of the columns are based on property values in an object (see "ProductVariantFacade" below), so I need to set the name of the columns after the grid has been initialized. So I started out using an ObservableCollection<ProductVariantFacade> in my view model, like so:
public ObservableCollection<ProductVariantFacade> ProductVariantFacades { get; set; }Where ProductVariantFacade looks like this:
public class ProductVariantFacade : FacadeBase { public ProductVariantFacade() { Data = new List<ProductVariantData>(); } private string rowName; public string RowName { get { return rowName; } set { if (value != rowName) { rowName = value; OnPropertyChanged("RowName"); } } } public List<ProductVariantData> Data { get; set; } public void AddData(string headerName, string value) { Data.Add(new ProductVariantData { HeaderName = headerName, Value = value }); } } public class ProductVariantData : FacadeBase { private string value; public string Value { get { return this.value; } set { if (value != this.value) { this.value = value; OnPropertyChanged("Value"); } } } private string headerName; public string HeaderName { get { return headerName; } set { if (value != headerName) { headerName = value; OnPropertyChanged("HeaderName"); } } } }The inherited FacadeBase implements INotifyPropertyChanged. Then my RadGridView's columns are set up as so:
<telerik:RadGridView Name="VariantDetailsGrid" AutoGenerateColumns="False" Height="130" IsReadOnly="False" ItemsSource="{Binding ProductVariantFacades, Mode=TwoWay}" > <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding RowName}" Header="" DataType="{x:Type sys:String}"/> <telerik:GridViewDataColumn DataMemberBinding="{Binding Data[0].Value}" DataType="{x:Type sys:String}"> <telerik:GridViewDataColumn.Header> <TextBlock Text="{Binding ProductVariantFacades[0].Data[0].HeaderName, Mode=TwoWay, Source={StaticResource ProductViewModel}}" /> </telerik:GridViewDataColumn.Header> </telerik:GridViewDataColumn><telerik:RadGridView.Columns></telerik:RadGridView>I was hoping that when I set my ObservableCollection ProductVariantFacades in my view model, the name of the column (the header) would be updated as well. That is, when the ProductVariantFacades[0].Data[0].HeaderName is set to a value. But for some reason this doesn't work. If I via a Button change the value of e.g. ProductVariantFacades[0].Data[0].Value it gets updated in the grid. But the header does not get updated when I change it. Any idea as to why?
Could it have anything to do with that the DataContext of TextBlock is not the same as for the rest of the view? E.g. not the same as the DataContext that the Data[0].Value is "connected" to?
Please help, thanks!