Esempio n. 1
0
		public MainWindowViewModel(IInteractionService message, IComicService comicManager, IPropertiesService properties)
		{
			Interaction = message;
			ComicManager = comicManager;
			Properties = properties;

			AddComicCommand = new RelayCommand(AddComic, (o) => !Downloading);
			AddRandomComicCommand = new AsyncRelayCommand(AddRandomComic);
			AddCurrentComicCommand = new AsyncRelayCommand(AddCurrentComic, (o) => !Downloading);
			RemoveComicCommand = new RelayCommand(RemoveComic, () => SelectedComic != null);
			ClearComicsCommand = new RelayCommand(() => Comics.Clear());

			LoadedCommand = new AsyncRelayCommand(Loaded);
			ClosedCommand = new AsyncRelayCommand(Closed);

			AboutCommand = new RelayCommand(About);
			ConfigurationCommand = new RelayCommand(Configuration);

			CopyLinkCommand = new RelayCommand(
				(o) => Interaction.SetClipboardText(string.Format(o as string, SelectedComic.Number)),
				(o) => SelectedComic != null && o is string);

			DeleteCacheCommand = new RelayCommand(
				() => SelectedComic?.DeleteCache(),
				() => SelectedComic != null);

			OpenLinkCommand = new RelayCommand(
				(o) => Interaction.StartProcess(string.Format(o as string, SelectedComic.Number)),
				(o) => SelectedComic != null && o is string);

			PropertyChanged += (o, e) =>
			{
				if (e.PropertyName == "SelectedComic")
				{
					RemoveComicCommand.RaiseCanExecuteChanged();
					DeleteCacheCommand.RaiseCanExecuteChanged();
					OpenLinkCommand.RaiseCanExecuteChanged();
					CopyLinkCommand.RaiseCanExecuteChanged();
				}

				if (e.PropertyName == "Downloading")
				{
					AddComicCommand.RaiseCanExecuteChanged();
					AddCurrentComicCommand.RaiseCanExecuteChanged();
					AddRandomComicCommand.RaiseCanExecuteChanged();
				}
			};
		}