This question is locked. New answers and comments are not allowed.
I have a control, when I need dislay person with two column:
-fullname
-best friend
The problem is , that property BestFriend on Person is an object.
At start Person has his own BestFriend, but he can change it from combobox column.
Now, after control loaded the column with bestfriend is blank.
When I doubleclick at this column I can change bestfirend, and it sets bestfriend of this person.
But what I must to do to have at start not blank column?
I think, that the problem is, that control can't match bestfriend, with collection of bestfriend, so I think that I must match them by id, but I don't know how can I do ti.
the main model:
and viewmodel:
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
and app xaml
I'm using 2010.1.603.1040
-fullname
-best friend
The problem is , that property BestFriend on Person is an object.
At start Person has his own BestFriend, but he can change it from combobox column.
Now, after control loaded the column with bestfriend is blank.
When I doubleclick at this column I can change bestfirend, and it sets bestfriend of this person.
But what I must to do to have at start not blank column?
I think, that the problem is, that control can't match bestfriend, with collection of bestfriend, so I think that I must match them by id, but I don't know how can I do ti.
<UserControl x:Class="MvvmLight1.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" Height="300" Width="300" DataContext="{Binding Main, Source={StaticResource Locator}}"> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Skins/MainSkin.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources> <Grid x:Name="LayoutRoot"> <telerik:RadGridView x:Name="grdSrL" AutoGenerateColumns="False" SelectionMode="Single" IsReadOnly="False" IsFilteringAllowed="True" Height="386" Width="460" HorizontalAlignment="Left" CanUserDeleteRows="False" CanUserInsertRows="True" CanUserReorderColumns="False" CanUserResizeColumns="True" ItemsSource="{Binding Persons}"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding FullName}" IsReadOnly="True" Header="FullName" /> <telerik:GridViewComboBoxColumn ItemsSource="{Binding Friends,Source={StaticResource Main}}" ItemsSourceBinding="{Binding Friends,Source={StaticResource Main}}" Header="1st" DataMemberBinding="{Binding BestFriend}" DisplayMemberPath="FullName" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid> </UserControl>the main model:
namespace MvvmLight1 { public class Person:INotifyPropertyChanged { private string _fullName; public string FullName { get { return _fullName; } set { if (_fullName!=value) { _fullName = value; OnPropertyChanged("FullName"); } } } public int Id { get { return _id; } set { _id = value; } } public Person BestFirend { get { return _bestFirend; } set { if (_bestFirend!=value) { _bestFirend = value; OnPropertyChanged("BestFirend"); } } } private int _id; private Person _bestFirend; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } }and viewmodel:
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;using GalaSoft.MvvmLight;namespace MvvmLight1.ViewModel{ public class MainViewModel : ViewModelBase { public MainViewModel() { for (int i = 0; i < 3; i++) { var friend = new Person() {FullName = "Name" + (i + 3).ToString()}; _friends.Add(friend); _persons.Add(new Person(){FullName = "Name"+i.ToString(),Id = i,BestFirend = friend}); } } private ObservableCollection<Person> _persons=new ObservableCollection<Person>(); public ObservableCollection<Person> Persons { get { return _persons; } set { _persons = value; } } public ObservableCollection<Person> Friends { get { return _friends; } set { _friends = value; } } private ObservableCollection<Person> _friends=new ObservableCollection<Person>(); }}and app xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x:Class="MvvmLight1.App" xmlns:vm="clr-namespace:MvvmLight1.ViewModel" mc:Ignorable="d"> <Application.Resources> <!--Global View Model Locator--> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> <vm:MainViewModel x:Key="Main"/> </Application.Resources></Application>I'm using 2010.1.603.1040