public int ShowWindow(ViewModelType type, IViewModel viewModel) { KeyValuePair<int, Window> k = this.CreateWindow(type, viewModel); viewModel.WindowId = k.Key; k.Value.Show(); return k.Key; }
private void SetViewModel(ViewModelType viewModelType) { this.currentOwnedViewModel?.Dispose(); this.currentViewModelType = viewModelType; this.currentOwnedViewModel = this.viewModelDictionary[viewModelType](); this.OnPropertyChanged(nameof(this.CurrentViewModel)); }
private KeyValuePair<int, Window> CreateWindow(ViewModelType type, IViewModel viewModel) { this.index++; Window window; switch (type) { case ViewModelType.LoginWindow: window = new LoginWindow {DataContext = viewModel}; break; case ViewModelType.MainWindow: window = new MainWindow {DataContext = viewModel}; break; case ViewModelType.SettingsWindow: window = new SettignsWindow { DataContext = viewModel }; break; default: window = new Window { DataContext = viewModel }; break; } window.DataContext = viewModel; KeyValuePair<int, Window> keyValuePair = new KeyValuePair<int, Window>(this.index, window); this.windows.Add(keyValuePair); return keyValuePair; }
public virtual List <TableColumn> GetTableColumns() { var props = ViewModelType.GetProperties().ToList(); var tableColumnProps = props.Where(prop => { var attr = prop.GetCustomAttributes <TableColumnAttribute>().FirstOrDefault(); return(attr != null && (!attr.Hidden || attr.RowGroup)); }).ToList(); if (tableColumnProps.Count == 0) { tableColumnProps = props; } tableColumnProps = tableColumnProps.Where(prop => { var attr = prop.GetCustomAttributes <TableColumnAttribute>().FirstOrDefault(); return(attr == null || !attr.Hidden || attr.RowGroup); }).ToList(); var list = tableColumnProps.Select(prop => new TableColumn(prop, prop.GetCustomAttributes <TableColumnAttribute>().ToList())).ToList(); if (!ExcludeActionsColumn) { list.Add(new TableColumn("", "_actions", 100) { Orderable = ServerClient.None, Searchable = ServerClient.None }); } return(list); }
public object Convert(object[] values, Type targetType, object paramater, CultureInfo culture) { ViewModelType viewModelParent = ((values[2] as FrameworkElement).DataContext) as ViewModelType; // Sneak in an update of viewmodelparent via physical parent. viewModelParent.HasVisibleChild = parentViewModel.EvaluateHasVisibleChild(); return((bool)values[0] && (bool)values[1] ? Visibility.Visible : Visibility.Collapsed); }
public ViewModelMembers(IViewModel instance, ViewModelType type) { _instance = instance; _type = type; _members = new Dictionary <string, IViewModelMember>(_type.MembersCount); _viewModels = new List <IViewModel>(_type.ViewModelsCount); }
public AlgorithmSelectionViewModel(ViewModelType type, ComboBox algorithmBox, AlgorithmControls algorithmControls, MainWindow mainWindow, TextBlock errorMessageTextBlock) : base(errorMessageTextBlock) { this.type = type; this.algorithmBox = algorithmBox; this.controls = algorithmControls; this.mainWindow = mainWindow; }
public ViewModelAttribute(Type vmType) { if (!ViewModelType.IsAssignableFrom(vmType)) { throw new ArgumentException("vmType must inherit from ViewModelBase"); } this.ViewModelType = vmType; }
public override int GetHashCode() { unchecked { int hashCode = 17; hashCode = hashCode * 23 + ViewModelType.GetHashCode(); hashCode = hashCode * 23 + ViewModelTag.GetHashCode(); return(hashCode); } }
async Task ExecuteNavigateCommand(ViewModelType arg) { try { await Navigate(arg); } catch (Exception ex) { await DisplayAlert("Erro!", ex.Message); } }
public CommonPage(ViewModelType vmType) : this() { //Cache our instance of our home page.. if (vmType == ViewModelType.Home) { NavigationCacheMode = NavigationCacheMode.Enabled; } CurrentViewModel = null; CurrentViewModelType = vmType; PageParam = ""; }
public override int GetHashCode() { int hash = 397; unchecked { hash = hash * 23 + ControlType.GetHashCode(); hash = hash * 23 + ViewModelType.GetHashCode(); //? Do we need to ensure that inherited classes offer a hash code? } return(hash); }
protected override void Configure() { _container .Singleton <IWindowManager, WindowManager>() .Singleton <IEventAggregator, EventAggregator>(); GetType().Assembly.GetTypes() .Where(type => type.IsClass) .Where(type => type.Name.EndsWith("ViewModel")) .ToList() .ForEach(ViewModelType => _container.RegisterPerRequest( ViewModelType, ViewModelType.ToString(), ViewModelType)); }
public static AlgorithmViewModel Create(string algorithmName, ViewModelType type, AlgorithmControls algorithmControls, MainWindow mainWindow, TextBlock errorMessageTextBlock) { return(type switch { ViewModelType.Basic => algorithmName switch { Lsb.ALGORITHM_NAME => new LsbViewModel(algorithmControls, mainWindow, errorMessageTextBlock), PixelAveraging.ALGORITHM_NAME => new PixelAveragingViewModel(algorithmControls, mainWindow, errorMessageTextBlock), Dwt.ALGORITHM_NAME => new DwtViewModel(algorithmControls, mainWindow, errorMessageTextBlock), Dft.ALGORITHM_NAME => new DftViewModel(algorithmControls, mainWindow, errorMessageTextBlock), Dct.ALGORITHM_NAME => new DctViewModel(algorithmControls, mainWindow, errorMessageTextBlock), _ => throw new ArgumentException($"Unknown algorithmName '{algorithmName}'."), },
public void BindText(Control control) { if (control.Tag != null) { PropertyInfo property = ViewModelType.GetProperty(control.Tag.ToString()); if (property != null) { string value = property.GetValue(ViewModel) as string; if (value != null) { SetText(control, value); } } } }
public static string AddVmTypePrefix(this string s, ViewModelType viewModelType) { if (string.IsNullOrEmpty(s)) { throw new ArgumentException("String is null"); } if (viewModelType == ViewModelType.block) { return(string.Format("vmBlock_{0}", s)); } else { return(string.Format("vmPage_{0}", s)); } }
public void FixMultiple(ViewModelType viewModelType, int limit = 99999) { DirectoryInfo dir = new DirectoryInfo(GetDirectoryForType(viewModelType)); var count = 0; foreach (var i in dir.GetFiles("*.schema")) { if (count == limit) { break; } var file = ReadFile(i.FullName); file = Fix(file); WriteSchemaFile(i.FullName, file); count++; } }
public ViewModelBase CreateViewModel(ViewModelType viewType) { switch (viewType) { case ViewModelType.Information: return(GetInformationControlViewModel()); case ViewModelType.Cleaner: return(GetCleanerControlViewModel()); case ViewModelType.Linker: return(GetLinkerControlViewModel()); default: return(_mainWindowViewModel); } }
protected override void Configure() { _container.Instance(_container); //Добавляем в контейнеры все наши интерфейсы и их реализацию _container .Singleton <IWindowManager, WindowManager>() .Singleton <IEventAggregator, EventAggregator>() .Singleton <IAPIHelpers, APIHelpers>(); GetType().Assembly.GetTypes() .Where(type => type.IsClass) .Where(type => type.Name.EndsWith("ViewModel")) .ToList() .ForEach(ViewModelType => _container.RegisterPerRequest( ViewModelType, ViewModelType.ToString(), ViewModelType)); }
public void RunAll(ViewModelType viewModelType, Dictionary <string, string> output = null, int limit = 99999) { DirectoryInfo dir = new DirectoryInfo(GetDirectoryForType(viewModelType)); var count = 0; foreach (var i in dir.GetFiles("*.schema")) { if (count == limit) { break; } (string Name, string Content)file = (Name : string.Empty, Content : string.Empty); try { file = generateViewmodelService.Create(i.FullName, i.Name.CleanFileExtension().RemoveFileSuffix(), viewModelType, builderConfig.ExcludeViewmodelsAtGeneration, blockPath, builderConfig.GeneratedViewmodelsNamespace); } catch (Exception ex) { throw new Exception(string.Format("Failed on schema file {0}", i.Name), ex); } foreach (var p in postProcessors) { if (p.IsValid(file.Name)) { file.Content = p.Apply(file.Content); } } if (file.Content.Contains("public partial class") || file.Content.Contains("public enum")) { if (output != null) { output.Add(file.Name, file.Content); } else { WriteOutputFile(file.Name, file.Content); } count++; } } }
public void BindCheckedState(Control control) { if (control.Tag != null) { PropertyInfo valueProperty = ViewModelType.GetProperty(control.Tag.ToString()); if (valueProperty != null) { PropertyInfo checkStateProperty = control.GetType().GetProperty("CheckState"); if (checkStateProperty != null) { control.On("CheckStateChanged", (o, a) => valueProperty.SetValue(ViewModel, checkStateProperty.GetValue(control))); object checkState = valueProperty.GetValue(ViewModel); checkStateProperty.SetValue(control, checkState); } } } }
private void BindEventHandlers(object tag, object target) { Type controlType = target.GetType(); if (tag != null) { controlType.GetEvents().Each(eventInfo => { MethodInfo method = ViewModelType.GetMethod("{0}On{1}"._Format(tag.ToString(), eventInfo.Name)); if (method != null) { Delegate d = Delegate.CreateDelegate(eventInfo.EventHandlerType, ViewModel, method); eventInfo.AddEventHandler(target, d); } }); } }
protected override void Configure() { _container.Instance(_container) .PerRequest <IProductEndpoint, ProductEndpoint>(); _container .Singleton <IWindowManager, WindowManager>() .Singleton <IEventAggregator, EventAggregator>() .Singleton <ILoggedInUserModel, LoggedInUserModel>() .Singleton <IConfigHelper, ConfigHelper>() .Singleton <IAPIHelper, APIHelper>(); GetType().Assembly.GetTypes() .Where(type => type.IsClass) .Where(type => type.Name.EndsWith("ViewModel")) .ToList() .ForEach(ViewModelType => _container.RegisterPerRequest(ViewModelType, ViewModelType.ToString(), ViewModelType)); }
async Task Navigate(ViewModelType type) { switch (type) { case ViewModelType.UmViewModel: await Navigation.PushAsync <UmViewModel>(true); break; case ViewModelType.DoisViewModel: await Navigation.PushAsync <DoisViewModel>(true); break; default: return; } }
public static void Cleanup(ViewModelType viewModelType) { switch (viewModelType) { case ViewModelType.Settings: UnRegisterSettingsViewModels(); break; case ViewModelType.MenuControl: SimpleIoc.Default.Unregister <MenuControlViewModel>(); SimpleIoc.Default.Unregister <SearchViewModel>(); break; case ViewModelType.MainWindow: UnRegisterMainWindowSettingsViewModels(); break; } }
async Task Navigate(ViewModelType type) { switch (type) { case ViewModelType.GetChartViewModel: await Navigation.PushAsync <GetChartViewModel>(true); break; case ViewModelType.UnitsViewModel: await Navigation.PushAsync <UnitsViewModel>(true); break; default: return; } }
public void BindDataSource(Control control) { ListControl listControl = control as ListControl; if (listControl != null) { object tag = listControl.Tag; if (tag != null) { string tagString = tag.ToString(); PropertyInfo dataSrcProp = ViewModelType.GetProperty("{0}DataSource"._Format(tagString)) ?? ViewModelType.GetProperty("{0}List"._Format(tagString)); if (dataSrcProp != null) { listControl.DataSource = dataSrcProp.GetValue(ViewModel); } } } }
public ViewModelType Resolve <ViewModelType>() { if (Container == null) { if (typeof(ViewModelType).IsInterface) { return(default(ViewModelType)); } else if (typeof(ViewModelType).IsClass) { // Note: Resolve should not return a null ViewModelType, so create an instance if necessary // This is necessary for VS Design mode viewing and for Blend return(Activator.CreateInstance <ViewModelType>()); } } ViewModelType viewModel = Container.Resolve <ViewModelType>(); viewModel = SetMockValues <ViewModelType>(viewModel); return(viewModel); }
public static BaseViewModel CreateViewModel(ViewModelType type) { switch (type) { case ViewModelType.Home: return(new HomeViewModel()); case ViewModelType.SearchResults: return(new SearchResultsViewModel()); case ViewModelType.AudioProductListing: case ViewModelType.CamerasProductListing: case ViewModelType.AppliancesProductListing: return(new ProductListingViewModel()); case ViewModelType.ViewProduct: return(new ViewProductViewModel()); case ViewModelType.CompareProducts: return(new CompareProductsViewModel()); } return(null); }
public void ShowDialogWindow(ViewModelType type, IViewModel viewModel) { KeyValuePair<int, Window> res = this.CreateWindow(type, viewModel); viewModel.WindowId = res.Key; res.Value.ShowDialog(); }
public override int GetHashCode() { return(ViewModelType.GetHashCode()); }
public static void Cleanup(ViewModelType viewModelType) { switch (viewModelType) { case ViewModelType.Settings: UnRegisterSettingsViewModels(); break; case ViewModelType.MenuControl: SimpleIoc.Default.Unregister<MenuControlViewModel>(); SimpleIoc.Default.Unregister<SearchViewModel>(); break; case ViewModelType.MainWindow: UnRegisterMainWindowSettingsViewModels(); break; } }
private void TryAddView(ViewType viewType, ViewModelType viewModelType, TweetListType columnType, string searchTerm, string searchName, Decimal? existingSearchID = null, MetroTwitStatusBase Tweet = null, TwitterList ListItem = null) { if (viewType == ViewType.Column) { this.TryAddColumn(false, (TweetListViewModel)null, columnType, searchTerm, searchName, existingSearchID); } else { if (viewType != ViewType.Popup) return; if (InlinePopup.CurrentInline != null) InlinePopup.CurrentInline.Close(); Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)this.MultiAccountifyToken((System.Enum)ViewModelMessages.SetNewTweetEntryOptionsContainer)); UserControl view = (UserControl)null; switch (viewModelType) { case ViewModelType.TweetList: if (columnType == TweetListType.Conversation) { string replyToScreenName = Tweet.InReplyToScreenName; TweetListViewModel tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, replyToScreenName, string.Empty, new Decimal?(), false, Tweet, Tweet.ID) { EnableNotifications = false, TitleBarVisible = false, SettingsVisible = false }; TweetListView tweetListView = new TweetListView(); tweetListView.DataContext = (object)tweetListViewModel; view = (UserControl)tweetListView; break; } else { TweetListViewModel tweetListViewModel; if (Tweet != null && Tweet.AdUrls != null && !string.IsNullOrEmpty(Tweet.AdUrls.friendship_url)) tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, searchTerm, searchName, new Decimal?(), false, (MetroTwitStatusBase)null, new Decimal(0)) { EnableNotifications = false, AdFollowUrl = Tweet.AdUrls.friendship_url, TitleBarVisible = false, SettingsVisible = false }; else tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, searchTerm, searchName, new Decimal?(), false, (MetroTwitStatusBase)null, new Decimal(0)) { EnableNotifications = false, TitleBarVisible = false, SettingsVisible = false }; tweetListViewModel.AllowPin = columnType != TweetListType.RetweetUsers; ProfileView profileView = new ProfileView(); profileView.DataContext = (object)tweetListViewModel; view = (UserControl)profileView; break; } case ViewModelType.Lists: ListsView listsView = new ListsView(); listsView.DataContext = (object)new ListsViewModel(this.TwitterAccountID) { PopupTitle = "lists", AllowPin = false }; view = (UserControl)listsView; break; case ViewModelType.Trends: TrendsView trendsView1 = new TrendsView(); TrendsView trendsView2 = trendsView1; TrendsViewModel trendsViewModel1 = new TrendsViewModel(); trendsViewModel1.TwitterAccountID = this.TwitterAccountID; trendsViewModel1.AllowPin = false; trendsViewModel1.PopupTitle = "twitter trends"; TrendsViewModel trendsViewModel2 = trendsViewModel1; trendsView2.DataContext = (object)trendsViewModel2; view = (UserControl)trendsView1; break; case ViewModelType.ManageList: ManageTwitterListView manageTwitterListView = new ManageTwitterListView(); manageTwitterListView.DataContext = (object)new ManageTwitterListViewModel(ListItem != null ? ListItem : (TwitterList)null, this.TwitterAccountID) { AllowPin = false, PopupTitle = (ListItem != null ? string.Format("Edit {0}", (object)ListItem.Name) : "create new list") }; view = (UserControl)manageTwitterListView; break; } PopupService.ShowView(view); } }
/// <summary> /// Adds a view model instance to the list of instances. /// </summary> /// <param name="viewModel">The view model instance to add.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModel"/> is <c>null</c>.</exception> /// <exception cref="WrongViewModelTypeException">The <paramref name="viewModel"/> is not of the right type.</exception> public void AddViewModelInstance(IViewModel viewModel) { Argument.IsNotNull("viewModel", viewModel); if (viewModel.GetType() != ViewModelType) { throw Log.ErrorAndCreateException(msg => new WrongViewModelTypeException(viewModel.GetType(), ViewModelType), "Cannot use view model type '{0}', expected type '{1}'", viewModel.GetType().GetSafeFullName(false), ViewModelType.GetSafeFullName(false)); } lock (_lock) { var vmId = viewModel.UniqueIdentifier; if (!_viewModelInstances.ContainsKey(vmId)) { _viewModelInstances.Add(vmId, viewModel); viewModel.PropertyChanged += OnViewModelPropertyChanged; var viewModelBase = viewModel as ViewModelBase; if (viewModelBase != null) { viewModelBase.CommandExecutedAsync += OnViewModelCommandExecutedAsync; } viewModel.SavingAsync += OnViewModelSavingAsync; viewModel.SavedAsync += OnViewModelSavedAsync; viewModel.CancelingAsync += OnViewModelCancelingAsync; viewModel.CanceledAsync += OnViewModelCanceledAsync; viewModel.ClosedAsync += OnViewModelClosedAsync; Log.Debug("Added view model instance, currently containing '{0}' instances of type '{1}'", _viewModelInstances.Count, ViewModelType); } } }
public ActionResult PostAction(ViewModelType model) { //model.AssociatedCard should contain your value }