void SetOriginalButtonColor() { try { List <FrameworkElement> lstElement; FreePlayPage page = (FreePlayPage)PageController.GetViewModel().CurrentPage; Panel pianoRoll = (Panel)page.pianoRoll.Content; UIElementCollection element = pianoRoll.Children; lstElement = element.Cast <FrameworkElement>().ToList(); Dictionary <string, string> _notesByKeys = PageController.GetPianoRollModel()._notesByKeys; List <string> pressedNotes = new List <string>(); var lstControl = lstElement.OfType <Button>(); foreach (var control in lstControl) { if (control.Tag.ToString() == _notesByKeys.FirstOrDefault(x => x.Value == NOTES[CurrentNote]).Key) { if (NOTES[CurrentNote].Contains("#")) { control.SetResourceReference(Button.StyleProperty, "BlackPianoKeyStyle"); } else { control.SetResourceReference(Button.StyleProperty, "WhitePianoKeyStyle"); } } } } catch (Exception) { IsPlaying = false; } }
private List <TextBox> GetAllTextBox() { List <TextBox> textBoxes = new List <TextBox>(); /// casting the content into panel Panel mainContainer = (Panel)this.Content; /// GetAll UIElement UIElementCollection element = mainContainer.Children; StackPanel controls = (StackPanel)element[0]; UIElementCollection element2 = controls.Children; /// casting the UIElementCollection into List List <FrameworkElement> lstElement = element2.Cast <FrameworkElement>().ToList(); /// Geting all Control from list var lstControl = lstElement.OfType <Control>(); foreach (Control control in lstControl) { if (control is TextBox) { textBoxes.Add((TextBox)control); } } return(textBoxes); }
private List <Button> castButtonsToList() { UIElementCollection element = uxGrid.Children; List <FrameworkElement> elements = element.Cast <FrameworkElement>().ToList(); List <Button> buttons = elements.OfType <Button>().ToList(); return(buttons); }
private void SetHexProperties(UIElementCollection hexes, double cellSize) { int charIndex = 0; List <Polygon> hexList = hexes.Cast <Polygon>().ToList(); foreach (Polygon element in hexList) { SetHexProperties(element, _permutedChars[charIndex++], cellSize); } }
public void DisableAllTiles() { UIElementCollection element = uxGrid.Children; List <FrameworkElement> elements = element.Cast <FrameworkElement>().ToList(); List <Button> buttons = elements.OfType <Button>().ToList(); foreach (Button b in buttons) { b.IsEnabled = false; } }
private void EnableAllControl(object sender, RoutedEventArgs e) { Panel mainContainer = (Panel)this.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); var lstControl = lstElement.OfType <Control>(); foreach (Control contol in lstControl) { contol.IsEnabled = true; } }
public MainWindow() { InitializeComponent(); //Initialize button list. UIElementCollection element = uxGrid.Children; List <FrameworkElement> elements = element.Cast <FrameworkElement>().ToList(); buttons = elements.OfType <Button>().ToList(); DoNewGame(); }
private void ClearBoard() { UIElementCollection element = uxGrid.Children; List <FrameworkElement> elements = element.Cast <FrameworkElement>().ToList(); List <Button> buttons = elements.OfType <Button>().ToList(); foreach (Button b in buttons) { b.Content = ""; b.IsEnabled = true; } }
private void UnlockTheKeyboard() { Panel mainContainer = (Panel)this.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> frameworkElements = element.Cast <FrameworkElement>().ToList(); var lstControl = frameworkElements.OfType <Button>(); foreach (Button btn in lstControl) { btn.IsEnabled = true; } }
/// <summary> /// Limpia los controles. /// </summary> private void ClearControls(Grid pControl) { UIElementCollection lObjelement = pControl.Children; List <FrameworkElement> lLstElement = lObjelement.Cast <FrameworkElement>().ToList(); var lLstControl = lLstElement.OfType <TextBox>(); foreach (TextBox lObjcontrol in lLstControl) { lObjcontrol.Text = string.Empty; lObjcontrol.BorderBrush = Brushes.Black; } }
private void DisableInputFields() { UIElementCollection elements = ((Panel)Content).Children; IEnumerable <Control> elementList = elements.Cast <FrameworkElement>().ToList().OfType <Control>(); foreach (Control control in elementList) { if (control is TextBox || control is ComboBox || control is DatePicker) { control.IsEnabled = false; } } }
/// <summary> /// Coloca los controles a su estado original. /// </summary> public static Grid ClearControls(Grid pObjGrid) { UIElementCollection lObjElements = pObjGrid.Children; List <FrameworkElement> lLstObjElements = lObjElements.Cast <FrameworkElement>().ToList(); var lLstObjControls = lLstObjElements.OfType <TextBox>(); foreach (TextBox lObjControl in lLstObjControls) { lObjControl.Text = string.Empty; lObjControl.BorderBrush = Brushes.Black; } return(pObjGrid); }
private void ClearAllControl(object sender, RoutedEventArgs e) { Panel mainContainer = (Panel)this.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); var lstControl = lstElement.OfType <Control>(); foreach (Control control in lstControl) { if (control is TextBox) { TextBox texBox = (TextBox)control; texBox.Clear(); } } }
public PianoRoll() { try { InitializeComponent(); viewModel = new PianoRollViewModel(); DataContext = viewModel; Panel mainContainer = (Panel)this.Content; UIElementCollection element = mainContainer.Children; lstElement = element.Cast <FrameworkElement>().ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private bool checkForWin() { UIElementCollection gridKid = uxGrid.Children; List <FrameworkElement> gridKids = gridKid.Cast <FrameworkElement>().ToList(); List <Button> buttons = gridKids.OfType <Button>().ToList(); string[] winCheck = new string[9]; for (var i = 0; i < 9; i++) { var winCK = buttons[i].Content; winCheck[i] = winCK.ToString(); } if ((winCheck[0] == "O" && winCheck[1] == "O" && winCheck[2] == "O") || (winCheck[3] == "O" && winCheck[4] == "O" && winCheck[5] == "O") || (winCheck[6] == "O" && winCheck[7] == "O" && winCheck[8] == "O") || (winCheck[0] == "O" && winCheck[3] == "O" && winCheck[6] == "O") || (winCheck[1] == "O" && winCheck[4] == "O" && winCheck[7] == "O") || (winCheck[2] == "O" && winCheck[5] == "O" && winCheck[8] == "O") || (winCheck[0] == "O" && winCheck[4] == "O" && winCheck[8] == "O") || (winCheck[2] == "O" && winCheck[4] == "O" && winCheck[6] == "O")) { MessageBox.Show(" 'O' Wins"); winner = true; newGame = false; } else if ((winCheck[0] == "X" && winCheck[1] == "X" && winCheck[2] == "X") || (winCheck[3] == "X" && winCheck[4] == "X" && winCheck[5] == "X") || (winCheck[6] == "X" && winCheck[7] == "X" && winCheck[8] == "X") || (winCheck[0] == "X" && winCheck[3] == "X" && winCheck[6] == "X") || (winCheck[1] == "X" && winCheck[4] == "X" && winCheck[7] == "X") || (winCheck[2] == "X" && winCheck[5] == "X" && winCheck[8] == "X") || (winCheck[0] == "X" && winCheck[4] == "X" && winCheck[8] == "X") || (winCheck[2] == "X" && winCheck[4] == "X" && winCheck[6] == "X")) { MessageBox.Show(" 'X' Wins"); winner = true; newGame = false; } else if (numClicks == 9) { MessageBox.Show("Tie Game No Winner"); winner = true; newGame = false; } return(winner); }
private void UxNewGame_Click(object sender, RoutedEventArgs e) { UIElementCollection gridKid = uxGrid.Children; List <FrameworkElement> gridKids = gridKid.Cast <FrameworkElement>().ToList(); List <Button> buttons = gridKids.OfType <Button>().ToList(); for (var i = 0; i < 9; i++) { buttons[i].Content = ""; buttons[i].IsEnabled = true; } MessageBox.Show("Begin new game"); player = true; winner = false; newGame = true; numClicks = 0; }
/// <summary> /// Valida los controles que se encuentran en blanco. /// </summary> private bool ValidateControls(Grid pObjBorder) { bool lBolValidate = true; UIElementCollection lObjelement = pObjBorder.Children; List <FrameworkElement> lLstElement = lObjelement.Cast <FrameworkElement>().ToList(); var lLstControl = lLstElement.OfType <TextBox>(); foreach (TextBox lObjcontrol in lLstControl) { if (string.IsNullOrEmpty(lObjcontrol.Text)) { lObjcontrol.BorderBrush = Brushes.Red; lBolValidate = false; } } return(lBolValidate); }
/// <summary> /// Valida los controles que se encuentran en blanco. /// </summary> public static Tuple <bool, Grid> ValidateControls(Grid pObjGrid) { bool lBolValidate = true; UIElementCollection lObjElements = pObjGrid.Children; List <FrameworkElement> lLstObjElements = lObjElements.Cast <FrameworkElement>().ToList(); var lLstObjControls = lLstObjElements.OfType <TextBox>(); foreach (TextBox lObjControl in lLstObjControls) { if (string.IsNullOrEmpty(lObjControl.Text)) { lObjControl.BorderBrush = Brushes.Red; lBolValidate = false; } } return(Tuple.Create(lBolValidate, pObjGrid)); }
public static void Validate(Window window, BaseViewModel model) { Panel mainContainer = (Panel)window.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); IEnumerable <Control> controls = lstElement.OfType <Control>(); ValidationContext context = new ValidationContext(model); List <ValidationResult.ValidationResult> results = new List <ValidationResult.ValidationResult>(); bool valid = Validator.TryValidateObject(model, context, results, true); if (valid == false) { foreach (ValidationResult.ValidationResult result in results) { foreach (string member in result.MemberNames) { PropertyInfo property = model.GetType().GetProperty(member); if (property != null) { DetailViewAttribute detailView = property.GetCustomAttribute <DetailViewAttribute>(); if (detailView != null) { Control control = window.FindName(detailView.ControlName) as Control; if (control != null) { DependencyProperty dependencyProperty = DependencyConnection[control.GetType()]; if (dependencyProperty != null) { BindingExpression bindingExpression = BindingOperations.GetBindingExpression(control, dependencyProperty); BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase(control, dependencyProperty); ValidationError validationError = new ValidationError(new DataErrorValidationRule(), bindingExpression); validationError.ErrorContent = result.ErrorMessage; Validation.MarkInvalid(bindingExpressionBase, validationError); } } } } } } } }
private void NightModeButtons(bool colorDay) { Panel mainContainer = (Panel)this.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); var lstControl = lstElement.OfType <Control>(); foreach (Control contol in lstControl) { if (contol is Button && colorDay == true) { (contol as Button).Background = new SolidColorBrush(Colors.LightSlateGray); } else if (contol is Button && colorDay == false) { (contol as Button).Background = new SolidColorBrush(Colors.White); } } }
public MainWindow() { InitializeComponent(); /// casting the content into panel Panel mainContainer = (Panel)this.Content; /// GetAll UIElement UIElementCollection element = mainContainer.Children; /// casting the UIElementCollection into List List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); /// Getting all Control from list var lstControl = lstElement.OfType <Control>(); foreach (var control in lstControl) { this.communicationManager .Register(control as Control); } this.components = new System.ComponentModel.Container(); this.loopTime = new System.Windows.Forms.Timer(this.components); this.loopTimer = new System.Windows.Forms.Timer(this.components); // loopTime // loopTime.Tick += new System.EventHandler(this.loopTime_Tick); this.loopTimer.Tick += (s, e) => { this.communicationManager.Poll(); }; this.clientBool = new TwinCAT.Ads.TcAdsClient(); this.clientBool.Connect(851); this.loopTimer.Enabled = true; this.loopTime.Enabled = true; this.loopTimer.Start(); }
public screenStartup() { InitializeComponent(); pageStartup = this; DBM.SQLInitialise(); populateServers(); MainWindow.main.ResizeMode = ResizeMode.NoResize; config = CFM.ReadSettings(); if (config[4] == "Light Theme") { } else if (config[4] == "Dark Theme") { VM.DarkTheme("screenStartup"); } Panel mainContainer = (Panel)this.Content; /// GetAll UIElement UIElementCollection element = mainContainer.Children; /// casting the UIElementCollection into List List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); /// Geting all Control from list var lstControl = lstElement.OfType <Control>(); foreach (Control control in lstControl) { Debug.WriteLine(control.GetType().ToString()); } if (Convert.ToBoolean(config[0]) == true) { this.cbRememberUser.IsChecked = true; this.tbStartupUsername.Text = config[1]; } }
/// <summary> /// Toggles the express inputs. /// </summary> private void ToggleInputs(Train selectedTrain) { ToggleElementsEnabled(allWindowElements.Cast <FrameworkElement>().ToList(), true); //resets all controls to enabled FilterStations(selectedTrain); var elementsToDisable = new List <FrameworkElement>(); if (!selectedTrain.OffersFirstClass) { elementsToDisable.Add(cbFirstClass); } if (selectedTrain.Type != Train.TrainType.Sleeper) { elementsToDisable.Add(cbCabin); } ToggleElementsEnabled(elementsToDisable, false); }
private void NumberStoryboardCompletedEventHandler(object sender, EventArgs e) { foreach (var tbk in scrollTextBlockList.Cast <TextBlock>()) { tbk.Text = ((int)tbk.Tag).ToString(); tbk.Margin = new Thickness(0); } int count = scrollTextBlockList.Count; if (lastNum.Length < count) { for (int i = 0; i < count - lastNum.Length; i++) { scrollTextBlockList.RemoveAt(0); } } stkScroll.Margin = new Thickness(0); storyboarding = false; }
/// <summary> /// Toggles the express inputs. /// </summary> private void ToggleInputs(string selectedType) { var intermediateStationInputs = allWindowElements.Cast <FrameworkElement>().Where(element => (string)element.Tag == "IntermediateStations").ToList(); //selects Intermediate Station checkboxes switch (selectedType) { case "Express": ToggleElementsEnabled(intermediateStationInputs, false); ClearCheckboxesWithTag("IntermediateStations"); return; case "Stopping": ToggleElementsEnabled(intermediateStationInputs, true); return; case "Sleeper": ToggleElementsEnabled(intermediateStationInputs, true); return; default: return; } }
public static void RedimensionaForm(Window window) { window.Width = Program.ResponsiveObj.GetMetrics(window.Width, "Width"); window.Height = Program.ResponsiveObj.GetMetrics(window.Height, "Height"); window.Left = Program.WidthScreen / 2 - window.Width / 2; window.Top = Program.HeightScreen / 2 - window.Height / 2 - 30; Panel mainContainer = (Panel)window.Content; UIElementCollection element = mainContainer.Children; List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); var lstControl = lstElement.OfType <Control>(); foreach (Control control in lstControl) { control.FontFamily = new FontFamily("Arial"); control.FontSize = Program.ResponsiveObj.GetMetrics(control.FontSize); control.FontStyle = FontStyles.Normal; control.Width = Program.ResponsiveObj.GetMetrics(control.Width, "Width"); control.Height = Program.ResponsiveObj.GetMetrics(control.Height, "Height"); Thickness t = new Thickness(Program.ResponsiveObj.GetMetrics(control.Margin.Left, "Top"), Program.ResponsiveObj.GetMetrics(control.Margin.Top, "Top"), control.Margin.Right, control.Margin.Bottom); control.Margin = t; } }
public static ProgressBar FindEmptyPogressBar(MainWindow window) { /// casting the content into panel Panel mainContainer = (Panel)window.Content; /// GetAll UIElement UIElementCollection element = mainContainer.Children; /// casting the UIElementCollection into List List <FrameworkElement> lstElement = element.Cast <FrameworkElement>().ToList(); /// Geting all Control from list var lstControl = lstElement.OfType <ProgressBar>(); foreach (var progressBar in lstControl) { if (progressBar.Value == 0) { return(progressBar); } } return(null); }
private void uxNewGame_Click(object sender, RoutedEventArgs e) { UIElementCollection element = uxGrid.Children; List <FrameworkElement> elements = element.Cast <FrameworkElement>().ToList(); List <Button> buttons = elements.OfType <Button>().ToList(); foreach (Button b in buttons) { b.Content = null; b.IsEnabled = true; } one = null; two = null; three = null; four = null; five = null; six = null; seven = null; eight = null; nine = null; turn = 0; }
private void btnLetter_Click(object sender, RoutedEventArgs e) { Button btnCurrent = sender as Button; bool gameWon = false; string txt = txtWord.Text; BitmapImage img; if (currentGame.progress == 0) { img = new BitmapImage(new Uri(ConfigurationManager.AppSettings["imgStart"])); } else { img = (BitmapImage)imgProgress.Source; } bool gameLost = Utils.letterTest(btnCurrent.Content.ToString(), ref currentGame, ref txt, ref img, ref gameWon); btnCurrent.IsEnabled = false; txtWord.Text = txt; imgProgress.Source = img; if (gameLost || gameWon) { Panel container = (Panel)this.Content; UIElementCollection elementCollection = container.Children; List <FrameworkElement> elementList = elementCollection.Cast <FrameworkElement>().ToList(); var buttons = elementList.OfType <Button>(); foreach (Button button in buttons) { button.IsEnabled = false; } if (gameWon && currentGame.level < 5) { imgProgress.Source = new BitmapImage(new Uri(ConfigurationManager.AppSettings["imgGameWon"])); txtWord.Foreground = new SolidColorBrush(Colors.DarkSeaGreen); MessageBox.Show("Level finished!", "", MessageBoxButton.OK); currentGame.level++; Utils.initializeGame(ref currentGame, Utils.categorySwich(currentGame.category)); currentGame.progress = 0; Utils.addGame(currentGame); GameWindow newGameWindow = new GameWindow(); newGameWindow.Show(); this.Close(); } else if (gameWon && currentGame.level == 5) { imgProgress.Source = new BitmapImage(new Uri(ConfigurationManager.AppSettings["imgGameWon"])); txtWord.Foreground = new SolidColorBrush(Colors.DarkSeaGreen); MessageBox.Show("Game won!", "", MessageBoxButton.OK); Utils.updatePlayer(currentGame.player.name, true); LoginWindow newWindow = new LoginWindow(); newWindow.Show(); this.Close(); } else { imgProgress.Source = new BitmapImage(new Uri(ConfigurationManager.AppSettings["imgGameLost"])); txtWord.Foreground = new SolidColorBrush(Colors.MediumVioletRed); if (MessageBox.Show("Game lost. \nDo you want to start a new game?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Game newGame = new Game(currentGame.player); newGame.level = 1; Utils.initializeGame(ref newGame, 0); newGame.usedLetters = new List <string>(); Utils.addGame(newGame); GameWindow newGameWindow = new GameWindow(); newGameWindow.Show(); } else { LoginWindow newWindow = new LoginWindow(); newWindow.Show(); } Utils.updatePlayer(currentGame.player.name, false); this.Close(); } } }
public static UIElement GetChildAt(UIElementCollection children, Point point) { return(GetChildAt(children.Cast <UIElement>(), point)); }