public CommonVM(MainVM main, BrieflyVM vm) { mainVM = main; brieflyVM = vm; Location = brieflyVM.Location; TemperatureVM = brieflyVM.ForecastModel?.GetTemperature(); City = brieflyVM.City; try { Icon = new BitmapImage(brieflyVM.Icon?.UriSource); Icon.Freeze(); } catch { }; }
public SearchVM(MainVM mainVM) { this.mainVM = mainVM; model = new SearchModel(); resource = new ResourceDictionary { Source = new Uri("pack://application:,,,/CustomColors.xaml") }; AdvancedSearchVM = new AdvancedSearchVM(); AdvancedSearchVM.PropertyChanged += (s, e) => { if (e.PropertyName == "StartSearch") { Search.Execute(); } }; GotFocus = new DelegateCommand(() => { var basePath = "pack://application:,,,/Resources/Icon"; SearchImage = new BitmapImage(new Uri($"{basePath}/search_black.png", UriKind.Absolute)); MenuImage = new BitmapImage(new Uri($"{basePath}/menu_black.png", UriKind.Absolute)); Background = "#FFDDDDDD"; Foreground = "#FF666666"; RaisePropertyChanged(nameof(SearchImage)); RaisePropertyChanged(nameof(MenuImage)); RaisePropertyChanged(nameof(Background)); RaisePropertyChanged(nameof(Foreground)); if (Query == defaultText) { Query = ""; RaisePropertyChanged(nameof(Query)); } }); LostFocus = new DelegateCommand(() => { var basePath = "pack://application:,,,/Resources/Icon"; SearchImage = new BitmapImage(new Uri($"{basePath}/search_white.png", UriKind.Absolute)); MenuImage = new BitmapImage(new Uri($"{basePath}/menu_white.png", UriKind.Absolute)); Background = resource["SearchBarColor"].ToString(); Foreground = resource["DeactiveTextColor"].ToString(); RaisePropertyChanged(nameof(SearchImage)); RaisePropertyChanged(nameof(MenuImage)); RaisePropertyChanged(nameof(Background)); RaisePropertyChanged(nameof(Foreground)); if (Query == "") { Query = defaultText; RaisePropertyChanged(nameof(Query)); } }); Search = new DelegateCommand(() => { if (isLoading) { return; } if (AdvancedSearchVM.SelectedCity != null) { // city selected RaisePropertyChanged("AdvancedSearchSelected"); isLoading = true; RaisePropertyChanged(nameof(LoadingVis)); } else { if (!IsValidQuery()) { return; } // search by query RaisePropertyChanged("QueryValid"); isLoading = true; RaisePropertyChanged(nameof(LoadingVis)); } }); Menu = new DelegateCommand(() => { IsShowDetailSearch = !IsShowDetailSearch; RaisePropertyChanged(nameof(IsShowDetailSearch)); }); mainVM.PropertyChanged += (s, e) => { if (e.PropertyName == "SearchLoadingCompleted") { isLoading = false; RaisePropertyChanged(nameof(LoadingVis)); } }; LostFocus.Execute(); }