// Add a new UserControl to Stack public void AddNewWS() { RateUserControl newRateMain = new RateUserControl(); newRateMain.ViewModel.ChangeView(true); MainStack.Children.Insert(0, newRateMain); }
public RateUserControlViewModel(RateDataUserControl rateDataControl, RateSetupUserControl setupWSRate, RateUserControl mainControl) { // Reference Children RateDataControl = rateDataControl; SetupWSRate = setupWSRate; //Refrence Main Control MainControl = mainControl; // Assign on click events of child controls RateDataControl.btnEditSettings.Click += new RoutedEventHandler(OnWSRateEditSettings); SetupWSRate.btnSave.Click += new RoutedEventHandler(OnWSRateSettingsSave); SetupWSRate.btnCancel.Click += new RoutedEventHandler(OnWSRateSettingsCancel); }
// Remove and Create User Controls From Main Stack public void CreateRaters() { try { MainStack.Children.RemoveRange(0, MainStack.Children.Count - 1); XMLRateUserContsols webservices = MainXMLHander.ReadXMLFile(); if ((webservices != null) && (webservices.WSRates.Count > 0)) { for (int z = 0; z < webservices.WSRates.Count; z++) { RateUserControl newWSRateMain = new RateUserControl(); RateUserDataControlViewModel model = newWSRateMain.ViewModel.RateDataControl.ViewModel; XMLRateUserControlData i = MainXMLHander.ReadXMLFile().WSRates[z]; newWSRateMain.VerticalAlignment = VerticalAlignment.Stretch; newWSRateMain.HorizontalAlignment = HorizontalAlignment.Stretch; newWSRateMain.Height = Double.NaN; newWSRateMain.Width = Double.NaN; model.RateType = i.Type; model.CurrencyFrom = i.CurrencyFrom; model.CurrencyTo = i.CurrencyTo; model.Symbol = i.Symbol; model.SelectedRefreshTime = model.RefreshTimes.Where(x => x.Key == i.RefreshTime).FirstOrDefault(); model.StartRatingThread(); MainStack.Children.Insert(0, newWSRateMain); WebServices.Add(newWSRateMain, i); } } } catch (Exception e) { MessageBox.Show("Could Not Create Controls : " + e.Message); } }
// Save new Controls to XML. public static void Save(RateUserControl control, XMLRateUserControlData newService) { WebServices[control] = newService; MainXMLHander.SaveServices(WebServices.ToList().Select(x => x.Value).ToList()); }