I have a WPF application with many labels.
....
You can make it with binding !
xaml view:
in code behind in the constructor:
DataContext = new ViewModelClass();
in ViewModelClass:
class ViewModelClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
private ObservableCollection _List = new ObservableCollection();
public ObservableCollection List
{
get { return _List; }
set
{
_List = value;
NotifyPropertyChanged("List");
}
}
public ViewModelClass()
{
List = new ObservableCollection
{
new StringObject {Value = "your"},
new StringObject {Value = "list"},
new StringObject {Value = "of"},
new StringObject {Value = "string"}
};
}
}
public class StringObject
{
public string Value { get; set; }
}
Be careful with a collection with type string
it doesn't work, you have to use an object => StringObject