class MyClassA
{
private ObservableCollection<AnotherClass> _listCode;
public ObservableCollection<AnotherClass> ListCode
{
get
{
return _listCode;
}
set
{
if (value == _listCode) return;
_listCode= value;
OnPropertyChanged("ListCode");
}
}
public void GetList()
{
ListCode = ...
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
<ListBox ItemsSource="{Binding Path=ListCode}" ItemTemplateSelector="{StaticResource ListTemplateSelector}" />
class MyClassA
{
public ObservableCollection<AnotherClass> ListCode { get; private set; };
public MyClassA()
{
// ...
ListCode = new ObservableCollection<AnotherClass>();
}
public void GetList()
{
ListCode.Clear();
// ...
ListCode.Add(new AnotherClass());
}
}
class MyClassA
{
public MyClassA {
GetList();
}
private ObservableCollection<AnotherClass> _listCode;
public ObservableCollection<AnotherClass> ListCode
{
get
{
return _listCode;
}
set
{
if (value == _listCode) return;
_listCode= value;
OnPropertyChanged("ListCode");
}
}
public void GetList()
{
ListCode = (берется из базы)
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public static MyClassA MyClassA;
public MainProgram()
{
InitializeComponent();
<b> MyClassA = new MyClassA ();</b>
DataContext = MyClassA;
}