Код: Выделить всё
Код: Выделить всё
public class CommandItem
{
public string CommandText { get; set; }
}
internal class ViewModel
{
public ObservableCollection Commands { get; set; }
private int _counter;
private Timer _timer;
public ViewModel()
{
Commands = new ObservableCollection();
_counter = 0;
_timer = new Timer(1000);
_timer.Elapsed += TimerElapsed;
}
public void StartAddingCommands()
{
if (!_timer.Enabled)
_timer.Start();
}
public void StopAddingCommands()
{
if (_timer.Enabled)
_timer.Stop();
}
private void TimerElapsed(object sender, ElapsedEventArgs e)
{
Application.Current.Dispatcher.Invoke(() =>
{
var newCommand = new CommandItem { CommandText = $"Command {_counter++}" };
Commands.Add(newCommand);
Console.WriteLine("Added Command: " + newCommand.CommandText);
});
}
Я попробовал это с помощью INotifyPropertyChanged, но ничего не изменилось.>
Подробнее здесь: https://stackoverflow.com/questions/788 ... in-listbox
Мобильная версия