Untitled

mail@pastecode.io avatar
unknown
csharp
3 years ago
1.1 kB
3
Indexable
Never
namespace MVVM_MWE1
{
	class MainWindowViewModel : BaseViewModel
	{

		public IEnumerable<string> ResourceIds => ModelDataFactory.AllData.Select(a => a.Name);

		private string _selectedItem;
		public string SelectedItem
		{
			get => _selectedItem;
			set
			{
				_selectedItem = value;
				FirePropertyChanged();
				OnSelectedItemChanged();
			}
		}

		private ModelDataContainer _selectedContainer;
		public ModelDataContainer SelectedContainer
		{
			get => _selectedContainer;
			private set
			{
				_selectedContainer = value;
				FirePropertyChanged();
			}
		}

		public ObservableCollection<ModelDataContainer> SelectedContainerHack { get; private set; }

		public MainWindowViewModel()
		{
			SelectedItem = ModelDataFactory.AllData.First().Name;
		}

		void OnSelectedItemChanged()
		{
			SelectedContainer = ModelDataFactory.AllData.Single(item => item.Name == SelectedItem);

			SelectedContainerHack = new ObservableCollection<ModelDataContainer>();
			SelectedContainerHack.Add(SelectedContainer);
		}
			
	}
}