This question is locked. New answers and comments are not allowed.
Hello,
I need to create a GridView with a view model for each column (each column's view model is sharing with an another object).
This is my code behind:
My XAML :
In child view model :
MonViewModel is my page view model (datacontext)
CourbeTypeViewModels is an ObservableCollection of CourbeTypeViewModel view model in MonViewModel
Points is an ObservableCollection<decimal> in each CourbeTypeViewModel
Tableau is a GridView in my page
This code creating 3 columns with header but without data...
My question : "How can I bind each column with it's own viewmodel ?"
I need to create a GridView with a view model for each column (each column's view model is sharing with an another object).
This is my code behind:
...
for (int i = 0; i < max; i++){ Binding MonBinding = new Binding("Points"); MonBinding.Source = MonViewModel.CourbeTypeViewModels[i]; MonBinding.Mode = BindingMode.OneWay; GridViewDataColumn GVDC = new GridViewDataColumn(); GVDC.DataMemberBinding = MonBinding; GVDC.UniqueName = "ValCT" + i.ToString(); GVDC.IsGroupable = false; GVDC.IsFilterable = false; GVDC.IsSortable = false; GVDC.IsReadOnly = true; Tableau.Columns.Add(GVDC);}
...My XAML :
...
<telerik:RadGridView Name="Tableau" AutoGenerateColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False"> <telerik:RadGridView.Columns/></telerik:RadGridView>
...In child view model :
...private ObservableCollection<decimal> _Points;public ObservableCollection<decimal> Points{ get { return _Points; } set { _Points = value; OnPropertyChanged("Points"); }}
...MonViewModel is my page view model (datacontext)
CourbeTypeViewModels is an ObservableCollection of CourbeTypeViewModel view model in MonViewModel
Points is an ObservableCollection<decimal> in each CourbeTypeViewModel
Tableau is a GridView in my page
This code creating 3 columns with header but without data...
My question : "How can I bind each column with it's own viewmodel ?"