public static bool IsPresent(Control control) { if (control.GetType().ToString() == "System.Windows.Forms.TextBox") { TextBox textBox = (TextBox)control; if (textBox.Text == "") { // MessageBox.Show(textBox.Tag.ToString() + " is a required field.", Title); // textBox.Focus(); return false; } else { return true; } } else if (control.GetType().ToString() == "System.Windows.Forms.ComboBox") { ComboBox comboBox = (ComboBox)control; if (comboBox.SelectedIndex == -1) { // MessageBox.Show(comboBox.Tag.ToString() + " is a required field.", Title); comboBox.Focus(); return false; } else { return true; } } return true; }
public static bool IsPresent(Control control) { if (control.GetType().ToString() == "System.Windows.Forms.TextBox") { TextBox textBox = (TextBox)control; if (textBox.Text == "") { //textBox.Focus(); return false; } else { return true; } } else if (control.GetType().ToString() == "System.Windows.Forms.ComboBox") { ComboBox comboBox = (ComboBox)control; if (comboBox.SelectedIndex == -1) { // comboBox.Focus(); return false; } else { return true; } } return true; }
/// <summary> /// load the specified control /// </summary> /// <param name="control"></param> public void LoadControlGoingback(System.Windows.Controls.Control control) { // verwijder het huidige item uit de navigatie int count = ApplicationState.GetValue <List <object> >(ApplicationVariables.listNavigationHistory).Count; ApplicationState.GetValue <List <object> >(ApplicationVariables.listNavigationHistory).RemoveAt(count - 1); // load the control ccPageContainer.Content = control; wfhTest.Child = null; ccPageContainer.Visibility = System.Windows.Visibility.Visible; wfhTest.Visibility = System.Windows.Visibility.Collapsed; svTest.Visibility = System.Windows.Visibility.Collapsed; //wfhTest.Height = 0; //wfhTest.Visibility = System.Windows.Visibility.Collapsed; // laad het menu if (control.GetType().BaseType == typeof(MenuControl)) { LoadMenu(((MenuControl)control)); // TODO: TEST OF DIT WEG MAG ((MenuControl)control).PageReloaded(); ((MenuControl)control).PageReloaded(); } else if (control.GetType().BaseType == typeof(WFControl)) { // kom je hier ooit in? // laadt menu voor WF Control LoadMenu(((MenuControl)control)); } // als het de navigatie is, de buttons reloaden else if (control.GetType().BaseType == typeof(NavigationControl)) { // maak menu onzichtbaar in het hoofdmenu gridMenu.Visibility = System.Windows.Visibility.Collapsed; ((NavigationControl)control).PageReloaded(); } else { // kom je hier ooit in? // laadt menu voor normaal Control LoadMenu(control); } }
public OKCancelControlContainer(Control control, string caption) : this() { Name = control.Name; if (string.IsNullOrEmpty(Name)) { var type = control.GetType(); //если контрол собственный, а Name не задан - то подставл¤ем им¤ типа Name = type.Namespace.StartsWith("System.")?null:type.Name; } if (string.IsNullOrEmpty(Name)) throw new ArgumentException(Properties.Resources.ControlNameCanNotBeEmpty); Title = caption; double initialViewWidth = control.Width; double initialViewHeight = control.Height; Width = initialViewWidth + 22; Height = initialViewHeight + 77; if (control.MinWidth != 0) MinWidth = control.MinWidth + 22; if (control.MinHeight != 0) MinHeight = control.MinHeight + 77; // if (control.MaxWidth != 0) // MaxWidth = control.MaxWidth + 22; // // if (control.MaxHeight != 0) // MaxHeight = control.MaxHeight + 77; control.Width = Double.NaN; control.Height = Double.NaN; Control = control; //если контрол может сам посылать сообщение о закрытии - то подключаем соответствующий обработчик if (control is IClosable) ((IClosable)control).CloseFired += ClosableControl_CloseFired; control.Focus(); }
/// <summary> /// Adds an element to the navigation stack. It deletes /// any forwarding element if the control type is different from /// the forwarding element of current view /// </summary> /// <param name="control"></param> public void Add(Control control) { if (NavigationStack.Count > 0 && _current > 0) { int curr = _current; for (int i = 0; i < curr; i++) { NavigationStack.Pop(); } _current = 0; } if (NavigationStack.Count == 0 || (NavigationStack.Count > 0 && control.GetType() != NavigationStack.Peek().GetType())) { NavigationStack.Push(control); _current = 0; } RaisePropertyChanged("Current"); RaisePropertyChanged("CurrentIndex"); }
public static void RefreshBinding(Control elementToUpdate) { object safelyCastedElement = elementToUpdate as TextBox; // For textbox. if (safelyCastedElement != null) { BindingExpression bindingExpression = elementToUpdate.GetBindingExpression(TextBox.TextProperty); RefreshBindingExpression(bindingExpression); return; } safelyCastedElement = elementToUpdate as ContentControl; // For content controls. if (safelyCastedElement != null) { BindingExpression bindingExpression = elementToUpdate.GetBindingExpression(ContentControl.ContentProperty); RefreshBindingExpression(bindingExpression); return; } Console.WriteLine("Log-Warning : " + string.Format("Binding update for type {0} is not supported.", elementToUpdate.GetType())); }
public MainWindow() { InitializeComponent(); _tempsize = DensityScrollViewer.ContentHorizontalOffset; Closing += (s, e) => ViewModelLocator.Cleanup(); Messenger.Default.Register <DataRoad>(this, "ShowInfo", message => { Info = message; }); Messenger.Default.Register <float>(this, "ShowInfoDistance", message => { Distance = message; }); Messenger.Default.Register <ObservableCollection <Graphics> >(this, "ShowGeneralGraff", message => GeneralGraff.DrawGraphic(message, collor = true)); var timer = new System.Windows.Threading.DispatcherTimer { Interval = new TimeSpan(0, 0, 1), IsEnabled = true }; timer.Tick += (o, t) => { TimeBlock.Text = " " + DateTime.Now.ToLongTimeString() + "\n" + DateTime.Now.ToLongDateString(); }; timer.Start(); Messenger.Default.Register <List <List <object> > >(this, "GreatGraphic", message => { LineSeries LS; AreaSeries AS; ColumnSeries CL; List <byte> CountGener; List <float> Distance; List <float> Layer123; List <double> Plotnost; List <Graphics> dataValues; LinearAxis linerAxx; LinearAxis linerAxy; Setter setter; Style style; Style legendStyle; Setter legendSetterw; Setter legendSetterl; AreaDataPoint areaDataPoint; int max; Control control; LineDataPoint lineDataPoint; Setter setterpoint; switch (_greatGraphicName) { case "CountChart": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.CountLayer = CountGener[i]; graph.Distance = Distance[i]; dataValues.Add(graph); } setter = new Setter(); setter.Property = BackgroundProperty; setter.Value = Brushes.Black; style = new Style(); var columnDataPoint = new ColumnDataPoint(); style.TargetType = columnDataPoint.GetType(); style.Setters.Add(setter); CL = new ColumnSeries { ItemsSource = dataValues, DependentValuePath = "CountLayer", IndependentValuePath = "Distance" }; CL.DataPointStyle = style; linerAxx = new LinearAxis(); linerAxy = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Minimum = 0; linerAxy.Maximum = 4; linerAxx.Title = "Расстояние, [м]"; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Количество слоёв", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(CL); LayoutRoot.Children.Add(chart); break; case "ChartLayer3": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №1", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DodgerBlue; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setterpoint); style.Setters.Add(setter); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer2": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer2 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №2", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DarkRed; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer1": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer1 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №3", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartAll": var Layer1 = new List <float>(); var Layer2 = new List <float>(); var Layer3 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer1.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } foreach (var count in message[2]) { Layer2.Add(Convert.ToByte(count)); } foreach (var count in message[3]) { Layer3.Add(Convert.ToByte(count)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer3[0]); for (var i = 0; i < Layer1.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer3[i]; graph.Layer2 = Layer2[i]; graph.Layer1 = Layer1[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer3[i] > max) { max = Convert.ToInt16(Layer3[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; //// var setter1 = new Setter(); var setterpoint1 = new Setter(); setterpoint1.Property = OpacityProperty; setterpoint1.Value = (double)0; setter1.Property = BackgroundProperty; setter1.Value = Brushes.OliveDrab; var style1 = new Style(); var areaDataPoint1 = new AreaDataPoint(); style1.TargetType = areaDataPoint1.GetType(); style1.Setters.Add(setter1); style1.Setters.Add(setterpoint1); var ser1 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance", Title = "Слой №3" }; ser1.DataPointStyle = style1; /// var setter2 = new Setter(); var setterpoint2 = new Setter(); setterpoint2.Property = OpacityProperty; setterpoint2.Value = (double)0; setter2.Property = BackgroundProperty; setter2.Value = Brushes.DarkRed; var style2 = new Style(); var areaDataPoint2 = new AreaDataPoint(); style2.TargetType = areaDataPoint2.GetType(); style2.Setters.Add(setter2); style2.Setters.Add(setterpoint2); var ser2 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance", Title = "Слой №2" }; ser2.DataPointStyle = style2; /// var setter3 = new Setter(); var setterpoint3 = new Setter(); setterpoint3.Property = OpacityProperty; setterpoint3.Value = (double)0; setter3.Property = BackgroundProperty; setter3.Value = Brushes.DodgerBlue; var style3 = new Style(); var areaDataPoint3 = new AreaDataPoint(); style3.TargetType = areaDataPoint3.GetType(); style3.Setters.Add(setter3); style3.Setters.Add(setterpoint3); var ser3 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", Title = "Слой №1" }; ser3.DataPointStyle = style3; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоёв", }; var setterlegendcollor = new Setter(); var setterlegendborder = new Setter(); setterlegendcollor.Property = BackgroundProperty; setterlegendcollor.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); setterlegendborder.Property = BorderBrushProperty; setterlegendborder.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); legendStyle = new Style(); control = new Control(); legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(setterlegendcollor); legendStyle.Setters.Add(setterlegendborder); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(ser3); chart.Series.Add(ser2); chart.Series.Add(ser1); LayoutRoot.Children.Add(chart); break; case "Plotnost": Plotnost = new List <double>(); Distance = new List <float>(); foreach (var count in message[0]) { Plotnost.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Plotnost[0]); for (var i = 0; i < Plotnost.Count - 1; i++) { var graph = new Graphics(); graph.IntensityN1 = Plotnost[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Plotnost[i] > max) { max = Convert.ToInt16(Plotnost[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "[кг/м^3]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); lineDataPoint = new LineDataPoint(); style.TargetType = lineDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); LS = new LineSeries() { ItemsSource = dataValues, DependentValuePath = "IntensityN1", IndependentValuePath = "Distance" }; LS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Плотность", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(LS); LayoutRoot.Children.Add(chart); break; case "GeneralGraff": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } var dataValues1 = new ObservableCollection <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.GeneralState = CountGener[i]; graph.Distance = Distance[i]; dataValues1.Add(graph); } Gridnorm = new Grid(); Gridd = new Graff(); Gridd.DrawGraphic(dataValues1, collor = false); Gridd.Width = 1111; Gridd.Height = 234; var text1 = new TextBlock(); var text2 = new TextBlock(); var collor1 = new TextBlock(); var collor2 = new TextBlock(); var collortext1 = new TextBlock(); var collortext2 = new TextBlock(); collor1.Background = Brushes.Red; collor2.Background = Brushes.Green; collor1.Width = 50; collor1.Height = 50; collor2.Width = 50; collor2.Height = 50; collor1.HorizontalAlignment = HorizontalAlignment.Left; collor1.VerticalAlignment = VerticalAlignment.Top; collor2.HorizontalAlignment = HorizontalAlignment.Left; collor2.VerticalAlignment = VerticalAlignment.Top; collor1.Margin = new Thickness(370, 650, 0, 0); collor2.Margin = new Thickness(690, 650, 0, 0); collortext1.Text = "- не соответствует"; collortext2.Text = "- соответствует"; collortext1.FontSize = 19; collortext2.FontSize = 19; collortext1.HorizontalAlignment = HorizontalAlignment.Left; collortext1.VerticalAlignment = VerticalAlignment.Top; collortext2.HorizontalAlignment = HorizontalAlignment.Left; collortext2.VerticalAlignment = VerticalAlignment.Top; collortext1.Margin = new Thickness(440, 657, 0, 0); collortext2.Margin = new Thickness(760, 657, 0, 0); text1.Text = "Общее состояние дорожного покрытия"; text2.Text = "Расстояние, [м]"; text2.FontStyle = FontStyles.Italic; text1.FontSize = 22; text2.FontSize = 19; text1.HorizontalAlignment = HorizontalAlignment.Left; text1.VerticalAlignment = VerticalAlignment.Top; text2.HorizontalAlignment = HorizontalAlignment.Left; text2.VerticalAlignment = VerticalAlignment.Top; text1.Margin = new Thickness(440, 350, 0, 0); text2.Margin = new Thickness(570, 530, 0, 0); Gridnorm.Children.Add(collortext1); Gridnorm.Children.Add(collortext2); Gridnorm.Children.Add(collor1); Gridnorm.Children.Add(collor2); Gridnorm.Children.Add(text1); Gridnorm.Children.Add(text2); Gridnorm.Children.Add(Gridd); Gridnorm.Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)); LayoutRoot.Children.Add(Gridnorm); Gridnorm.MouseLeftButtonDown += MouseLeftButtonDownGrid1; Gridd.MouseLeftButtonDown += MouseLeftButtonDownGrid1; break; } }); }
private static CommandBehaviorBase<Control> CreateCommandBehavior(Control control, String eventName) { var type = control.GetType(); var behavior = new CommandBehaviorBinder<Control>(control); var info = type.GetEvent(eventName); if (info != null) { var methodInfo = behavior.GetType().GetMethod("Execute"); var handler = Delegate.CreateDelegate(info.EventHandlerType, behavior, methodInfo, true); info.AddEventHandler(control, handler); } else { throw new ArgumentException(String.Format("Target object '{0}' doesn't have the event '{1}'.", type.Name, eventName)); } return behavior; }
/// <summary> /// Checks the spelling of the specified control. /// </summary> /// <param name="control"> /// The control. /// </param> /// <returns> /// The spell checking task. /// </returns> public async Task<SpellCheckingResult> CheckSpelling(Control control) { if (control == null) throw new ArgumentNullException("control"); var culture = GetCulture(control); SpellCheck.SetCulture(control, culture); var getUserDictionaryTask = GetUserDictionaryAsync(); var getDictionaryTask = GetDictionaryAsync(culture); var getIgnoredWordsTask = GetIgnoredWordsAsync(); await TaskEx.WhenAll(getUserDictionaryTask, getDictionaryTask, getIgnoredWordsTask); var userDictionary = getUserDictionaryTask.Result; var dictionary = getDictionaryTask.Result; var ignoredWords = getIgnoredWordsTask.Result; var richTextBox = control as RadRichTextBox; if (richTextBox != null) { var dialog = new CustomSpellCheckingDialog(); var spellChecker = (DocumentSpellChecker)richTextBox.SpellChecker; spellChecker.AddDictionary(dictionary, culture); spellChecker.RemoveCustomDictionary(culture); spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture); spellChecker.AddCustomDictionary(userDictionary, CultureInfo.InvariantCulture); richTextBox.IgnoredWords = ignoredWords; spellChecker.SpellCheckingCulture = culture; return await dialog.ShowDialog(new SpellCheckingUIManager(richTextBox), richTextBox); } else { var controlSpellChecker = ControlSpellCheckersManager.GetControlSpellChecker(control.GetType()); if (controlSpellChecker == null) throw new NotImplementedException("No spellcheck for this type of control."); var spellChecker = (DocumentSpellChecker)controlSpellChecker.SpellChecker; spellChecker.AddDictionary(dictionary, culture); spellChecker.RemoveCustomDictionary(culture); spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture); spellChecker.AddCustomDictionary(userDictionary, CultureInfo.InvariantCulture); controlSpellChecker.IgnoredWords = ignoredWords; spellChecker.SpellCheckingCulture = culture; controlSpellChecker.CurrentControl = control; var checkAllAtOnceWindow = new SpellCheckAllAtOnceWindow(); return await checkAllAtOnceWindow.ShowDialog(controlSpellChecker); } }
private static void addSubitem(IEnumerable<Tuple<string, string, int>> tableList, Control item) { try { if (item.GetType() != typeof(MenuItem)) return; var tempMenus = new List<Control>(); tempMenus.AddRange(((MenuItem)item).Items.Cast<Control>()); ((MenuItem)item).Items.Clear(); var enumerable = tableList as Tuple<string, string, int>[] ?? tableList.ToArray(); foreach ( var tm in enumerable.Where(tb => tb.Item2 == item.Name) .Select(tp => tempMenus.FirstOrDefault(m => m.Name == tp.Item1)) .Where(tm => tm != null)) { ((MenuItem)item).Items.Add(tm); addSubitem(enumerable, tm); } } catch (Exception ex) { PNStatic.LogException(ex); } }
/// <summary> /// Convert full name of the control to name that will be used for /// creation of bookmakrs /// </summary> /// <param name="control"> /// User Control or Control object that can be used /// by navigator as a target. /// </param> /// <returns>Short name of control used for bookmarks</returns> public string ControlToControlName(Control control) { return control.GetType().AssemblyQualifiedName; }
/// <summary> /// Tries to set user controls to what they were last time the user used the app /// </summary> public static void SaveControlSettings(Control control) { try { if (control.GetType() == typeof(TextBox)) { var textbox = control as TextBox; if (textbox == null) return; Set(textbox.Name, textbox.Text); } else if (control.GetType() == typeof(TextPlaceholder)) { var textbox = control as TextPlaceholder; if (textbox == null) return; Set(textbox.Name, textbox.Text); } else if (control.GetType() == typeof(ComboBox)) { var combobox = control as ComboBox; if (combobox == null) return; var elemIndex = combobox.SelectedIndex; if (elemIndex != -1) Set(combobox.Name, elemIndex.ToString()); } else if (control.GetType() == typeof(CheckBox)) { var checkbox = control as CheckBox; if (checkbox == null || !checkbox.IsChecked.HasValue) return; Set(checkbox.Name, checkbox.IsChecked.Value.ToString()); } else if (control.GetType() == typeof(TabControl)) { var tabcontrol = control as TabControl; if (tabcontrol == null) return; Set(tabcontrol.Name, tabcontrol.SelectedIndex.ToString()); } } catch (Exception ex) { Console.Write(ex.Message); } }
/// <summary> /// Tries to set user controls to what they were last time the user used the app /// </summary> public static void LoadControlSettings(Control control) { try { if (control.GetType() == typeof(TextBox)) { var textbox = control as TextBox; if (textbox == null) return; var value = Get(textbox.Name); if (!string.IsNullOrEmpty(value)) textbox.Text = value; } else if (control.GetType() == typeof(TextPlaceholder)) { var textbox = control as TextPlaceholder; if (textbox == null) return; var value = Get(textbox.Name); if (!string.IsNullOrEmpty(value)) textbox.Text = value; } else if (control.GetType() == typeof(ComboBox)) { var combobox = control as ComboBox; if (combobox == null) return; var value = Get(combobox.Name); if (!string.IsNullOrEmpty(value)) { int elemIndex = 0; int.TryParse(value, out elemIndex); if (combobox.Items.Count > elemIndex) combobox.SelectedIndex = elemIndex; } } else if (control.GetType() == typeof(CheckBox)) { var checkbox = control as CheckBox; if (checkbox == null) return; bool value; if (Boolean.TryParse(Get(checkbox.Name), out value)) checkbox.IsChecked = value; } else if (control.GetType() == typeof(TabControl)) { var tabcontrol = control as TabControl; if (tabcontrol == null) return; int value; if (int.TryParse(Get(tabcontrol.Name), out value)) tabcontrol.SelectedIndex = value; } } catch (Exception ex) { Console.Write(ex.Message); } }
private void attend_on_item(bool select, Control i) { if (i.GetType() != Type.GetType("nature_net.user_controls.collection_listbox_item") && i.GetType() != Type.GetType("nature_net.user_controls.item_generic_v2")) return; if (select) { if (i.GetType() != Type.GetType("nature_net.user_controls.collection_listbox_item")) i.Background = Brushes.LightGray; else i.Opacity = configurations.click_opacity_on_collection_item; } else { i.Background = Brushes.Transparent; i.Opacity = 1; } }
private static void TogglePadding(Control control) { control.Padding = control.Padding.Left == 0 ? new Thickness(10) : new Thickness(0); Output.Write(control.GetType().Name); Output.Write("Padding: " + control.Padding); Output.Break(); }
/// <summary> /// Checks some default properties not empty or null for the control. /// </summary> /// <param name="control">The control that is verified</param> /// <returns>true if one property is found on the control and is empty or null; false otherwise</returns> private static bool CheckDefaultPropertiesEmptyOrNull(Control control) { // For Password var passwordPropertyInfo = control.GetType().GetProperty("Password"); if (passwordPropertyInfo != null && passwordPropertyInfo.GetValue(control, null).ToString() == string.Empty) { return true; } // For rich textbox var richTextBoxPropertyInfo = control.GetType().GetProperty("Document"); if (richTextBoxPropertyInfo != null) { var richTextBoxvalue = richTextBoxPropertyInfo.GetValue(control, null) as FlowDocument; if (richTextBoxvalue != null) { var textRange = new TextRange(richTextBoxvalue.ContentStart, richTextBoxvalue.ContentEnd); if (string.IsNullOrWhiteSpace(textRange.Text)) { return true; } } } // For Selector var comboboxPropertyInfo = control.GetType().GetProperty("SelectedItem"); if (comboboxPropertyInfo != null && comboboxPropertyInfo.GetValue(control, null) == null) { return true; } // For textbox var textPropertyInfo = control.GetType().GetProperty("Text"); return textPropertyInfo != null && textPropertyInfo.GetValue(control, null).ToString() == string.Empty; }
/// <summary> /// Verifies if the property sent as parameter has its default value. /// </summary> /// <param name="tb">The control.</param> /// <param name="stringProperty">The string property.</param> /// <returns>True if the property has the default value; false otherwise</returns> private static bool PropertyIsEmpty(Control tb, string stringProperty) { var propertyIsEmpty = false; var propertyInfo = tb.GetType().GetProperty(stringProperty); if (propertyInfo != null) { var propertyType = propertyInfo.DeclaringType; var defaultValue = propertyType != null && (propertyType.IsValueType && !(propertyType == typeof(void))) ? Activator.CreateInstance(propertyType) : null; if (propertyInfo.GetValue(tb, null) == defaultValue) { propertyIsEmpty = true; } } return propertyIsEmpty; }
private XElement ExtractTagFromControl(Control uc) { XElement componentTag = null; if (uc.GetType() == typeof(CManager.ItBox)) { ItBox ibox = (ItBox)uc; var lbi = (ListBoxItem)ibox.Parent; lbi.IsSelected = true; componentTag = (XElement)lbi.Tag; } else if (uc.GetType() == typeof(ListBox)) { ListBox lbox = (ListBox)uc; lbox.UnselectAll(); var selected = (TreeViewItem)this.treeView1.SelectedItem; var v = selected.Tag; componentTag = (XElement)v; } else if (uc.GetType() == typeof(TreeViewItem)) { componentTag = (XElement)uc.Tag; } else if (uc.GetType() == typeof(TVItem)) { componentTag = (XElement)(uc.Parent as Control).Tag; } else { } return componentTag; }
private void ValidateType(Control control) { if (control is ButtonBase || control is MenuItem) return; throw new NotSupportedException("Type not supported: " + control.GetType().Name + "!"); }