public static MenuItem CreateComboBox(string cbName, float value, List <float> values, string format, string label, int textWidth, RoutedEventHandler theEventHandler) { StackPanel sp = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 3, 3, 3) }; sp.Children.Add(new Label { Content = label, Padding = new Thickness(0) }); ComboBox theCombo = new ComboBox { IsEditable = true, Width = textWidth, Name = cbName }; theCombo.Text = format.IndexOf("X") == -1 ? value.ToString(format) : ((int)value).ToString(format); for (int i = 0; i < values.Count; i++) { theCombo.Items.Add(format.IndexOf("X") == -1 ? values[i].ToString(format) : ((int)values[i]).ToString(format)); } theCombo.AddHandler(TextBox.TextChangedEvent, theEventHandler); theCombo.AddHandler(ComboBox.SelectionChangedEvent, theEventHandler); sp.Children.Add(theCombo); return(new MenuItem { StaysOpenOnClick = true, Header = sp }); }
public static ComboBox CreateComboBox(string cbName, float value, List <float> values, string format, int textWidth, RoutedEventHandler theEventHandler) { ComboBox theCombo = new ComboBox { IsEditable = true, Width = textWidth, Name = cbName }; theCombo.Text = format.IndexOf("X") == -1 ? value.ToString(format) : ((int)value).ToString(format); for (int i = 0; i < values.Count; i++) { theCombo.Items.Add(format.IndexOf("X") == -1 ? values[i].ToString(format) : ((int)values[i]).ToString(format)); } theCombo.AddHandler(TextBox.TextChangedEvent, theEventHandler); theCombo.AddHandler(ComboBox.SelectionChangedEvent, theEventHandler); return(theCombo); }
/// <summary> /// Binds the event handlers for to a <see cref="Control"/>. /// </summary> /// <param name="control">A <see cref="Control"/>.</param> private static void BindControl(Control control) { control.Loaded -= ControlLoaded; control.Loaded += ControlLoaded; control.GotKeyboardFocus -= ControlGotKeyboardFocus; control.GotKeyboardFocus += ControlGotKeyboardFocus; control.LostKeyboardFocus -= ControlLostKeyboardFocus; control.LostKeyboardFocus += ControlLostKeyboardFocus; TextBox textBox = control as TextBox; if (textBox != null) { textBox.TextChanged -= TextBoxTextChanged; textBox.TextChanged += TextBoxTextChanged; } ComboBox comboBox = control as ComboBox; if (comboBox != null) { comboBox.SelectionChanged -= ComboBoxSelectionChanged; comboBox.SelectionChanged += ComboBoxSelectionChanged; comboBox.RemoveHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler(ComboBoxTextChanged)); comboBox.AddHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler(ComboBoxTextChanged)); } }
private Control Layout(Panel Container, ListSingleField Field, DataForm _) { this.LayoutControlLabel(Container, Field); ComboBox ComboBox = new ComboBox() { Name = VarToName(Field.Var), IsReadOnly = Field.ReadOnly, ToolTip = Field.Description, Margin = new Thickness(0, 0, 0, 5) }; if (Field.HasError) { ComboBox.Background = new SolidColorBrush(Colors.PeachPuff); } else if (Field.NotSame) { ComboBox.Background = new SolidColorBrush(Colors.LightGray); } ComboBoxItem Item; foreach (KeyValuePair <string, string> P in Field.Options) { Item = new ComboBoxItem() { Content = P.Key, Tag = P.Value }; ComboBox.Items.Add(Item); } if (Field.ValidationMethod is Networking.XMPP.DataForms.ValidationMethods.OpenValidation) { ComboBox.IsEditable = true; ComboBox.Text = Field.ValueString; ComboBox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new System.Windows.Controls.TextChangedEventHandler(ComboBox_TextChanged)); } else { string s = Field.ValueString; ComboBox.IsEditable = false; ComboBox.SelectedIndex = Array.FindIndex <KeyValuePair <string, string> >(Field.Options, (P) => P.Value.Equals(s)); ComboBox.SelectionChanged += this.ComboBox_SelectionChanged; } Container.Children.Add(ComboBox); ComboBox.Tag = this.LayoutErrorLabel(Container, Field); return(ComboBox); }
public ComboBoxHintProxy(ComboBox comboBox) { if (comboBox == null) { throw new ArgumentNullException(nameof(comboBox)); } _comboBox = comboBox; _comboBoxTextChangedEventHandler = ComboBoxTextChanged; _comboBox.AddHandler(TextBoxBase.TextChangedEvent, _comboBoxTextChangedEventHandler); _comboBox.SelectionChanged += ComboBoxSelectionChanged; _comboBox.Loaded += ComboBoxLoaded; _comboBox.IsVisibleChanged += ComboBoxIsVisibleChanged; }
public ComboBoxAdapter(IParameterDescriptor parameter, ComboBox comboBox, Action updateCallback) { _parameter = parameter; _comboBox = comboBox; _updateAction = updateCallback; if (comboBox.IsEditable) { _textCallbackLock = new ReferenceCounter(); comboBox.Loaded += ComboBox_OnLoaded; comboBox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new TextChangedEventHandler(ComboBoxTextBox_TextChanged)); } else { _textCallbackLock = null; } }
public ComboBoxAdapter(IParameterDescriptor parameter, Type actualValueType, ComboBox comboBox, Action updateAction) { _parameter = parameter; _actualValueType = actualValueType; _comboBox = comboBox; _updateAction = updateAction; if (comboBox.IsEditable) { _textCallbackLock = new ReferenceCounter(); comboBox.Loaded += ComboBox_OnLoaded; comboBox.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, new TextChangedEventHandler(ComboBoxTextBox_TextChanged)); } else { _textCallbackLock = null; comboBox.SizeChanged += ComboBox_OnSizeChanged; } comboBox.SelectionChanged += ComboBoxComboBoxOnSelectionChanged; }
/// <summary> /// Invoked when the effective value of the <see cref="HintProperty"/> changes. /// </summary> /// <param name="sender">The <see cref="DependencyObject"/> on which the <see cref="HintProperty"/> has changed /// value.</param> /// <param name="e">Event data that is issued by any event that tracks changes to the effective value of this /// property.</param> private static void HintPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if (!(sender is TextBox) && !(sender is ComboBox)) { return; } Control control = (Control)sender; control.Loaded -= ControlLoaded; control.Loaded += ControlLoaded; control.GotKeyboardFocus -= ControlGotKeyboardFocus; control.GotKeyboardFocus += ControlGotKeyboardFocus; control.LostKeyboardFocus -= ControlLostKeyboardFocus; control.LostKeyboardFocus += ControlLostKeyboardFocus; TextBox textBox = control as TextBox; if (textBox != null) { textBox.TextChanged -= TextBoxTextChanged; textBox.TextChanged += TextBoxTextChanged; } ComboBox comboBox = control as ComboBox; if (comboBox != null) { comboBox.SelectionChanged -= ComboBoxSelectionChanged; comboBox.SelectionChanged += ComboBoxSelectionChanged; comboBox.RemoveHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler(ComboBoxTextChanged)); comboBox.AddHandler(TextBoxBase.TextChangedEvent, new RoutedEventHandler(ComboBoxTextChanged)); } UpdateWatermark(control); }
public ComboBoxAdapter([NotNull] IParameterDescriptor parameter, [CanBeNull] ITypeConverter textConverter, [NotNull] ComboBox comboBox, [CanBeNull] Button refreshButton) { _parameter = parameter; _textConverter = textConverter; _comboBox = comboBox; _refreshButton = refreshButton; _comboBox.SelectionChanged += ComboBox_OnSelectionChanged; if (comboBox.IsEditable) { if (textConverter == null) { throw new ArgumentNullException(nameof(textConverter)); } comboBox.Loaded += ComboBox_OnLoaded; comboBox.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(ComboBoxTextBox_OnTextChanged)); } if (_refreshButton != null) { _refreshButton.Click += RefreshButton_OnClick; } }
private UIElement Element(int id) { dynamic element = null; switch (id) { case 0: element = new Label() { Style = Resources["ParamLabel"] as Style, Content = Encryption.currentAlg == 3 ? "128" : "64" }; break; case 1: if (Encryption.currentAlg == 1) { element = new Label() { Style = Resources["ParamLabel"] as Style, Content = "64" } } ; else if (Encryption.currentAlg == 4) { element = new WrapPanel(); element.Children.Add(new TextBox() { Style = Resources["MainTextBox"] as Style, Width = 50, Text = Encryption.algParams[1].ToString() }); element.Children[0].AddHandler(TextBox.TextChangedEvent, new RoutedEventHandler(BlockSize)); var buttons = new StackPanel(); buttons.Children.Add(new Button() { Style = Resources["AddButton"] as Style, Content = '+' }); buttons.Children[0].AddHandler(Button.ClickEvent, new RoutedEventHandler(PlusButton)); buttons.Children.Add(new Button() { Style = Resources["AddButton"] as Style, Content = '-' }); buttons.Children[1].AddHandler(Button.ClickEvent, new RoutedEventHandler(MinusButton)); element.Children.Add(buttons); } else { var items = Encryption.currentAlg == 2 ? new List <string>() { "128", "192" } : new List <string>() { "128", "192", "256" }; element = new ComboBox() { Width = 100, Margin = new Thickness(5, 0, 0, 0), ItemsSource = items, SelectedIndex = items.IndexOf(Encryption.algParams[1].ToString()) }; element.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(BlockSize)); } break; case 2: element = new Label() { Style = Resources["ParamLabel"] as Style, Content = Encryption.currentAlg == 1 ? "16" : Encryption.currentAlg == 2 ? "16 * 3" : Encryption.currentAlg == 3 ? "10, 12, 14" : Encryption.currentAlg == 4 ? "15 + 3" : null }; break; } return(element); }
private void AddColumnHeaders() { // Starting in column 1 (because 0 row and column are used for size // configuration) add elements to the column headers. for (int i = 1; i < this.gridLayout.ColumnDefinitions.Count; i++) { // Create and add the combo box. var cbo = new ComboBox { FontSize = 10, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(10), IsTabStop = false, Tag = i }; // Create a list of names from the enumeration string[] ary = Enum.GetNames(typeof(ControlType)); Array.Sort(ary); // Create the values for the comboBox string nextString = string.Empty; string currentString = string.Empty; for (int j = 0; j < ary.Length; j++) { if (nextString == string.Empty) { nextString = "Select"; } if (ary[j] == "None") { ary[j] = nextString; break; } currentString = ary[j]; ary[j] = nextString; nextString = currentString; } cbo.ItemsSource = ary; // Needs to follow above loop to have something to select cbo.SelectedValue = "Select"; cbo.AddHandler(Selector.SelectionChangedEvent, new SelectionChangedEventHandler(this.cboColumnHeader_SelectionChanged)); this.ColumnHeaderComboBoxCollection.Add(cbo); // Create the root element of the editor. var sp = new StackPanel(); // cbo goes into a StackPanel. sp.Children.Add(cbo); // Create and add a text block to show the width of the column. var tb = new TextBlock { Tag = i - 1, Margin = new Thickness(5), HorizontalAlignment = HorizontalAlignment.Center, Text = this.ParseGridLength(this.ColumnWidthsCollection[i]), ToolTip = "Right click to edit this column's size" }; tb.AddHandler(MouseRightButtonDownEvent, new MouseButtonEventHandler(this.ColumnTextBlock_MouseRightButtonDown)); this.ColumnHeaderTextBlockCollection.Add(tb); // tb goes into the StackPanel sp.Children.Add(tb); // Set the column property of the stack panel. sp.SetValue(Grid.ColumnProperty, i); // StackPanel into the grid. this.gridLayout.Children.Add(sp); } }
/// <summary> /// 具体刷新Tab内容的方法 /// </summary> /// <param name="tab"></param> private void RefreshTabContent(TabItem tab) { //logger.Debug("刷新控件ing"); if (tab.Tag == null) { return; } int index = (int)tab.Tag; var prompts = viewModel.Prompts.Where(it => it.TabIndex == index) .ToList(); Grid grid = new Grid(); ScrollViewer viewer = new ScrollViewer(); viewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; viewer.Content = grid; tab.Content = viewer; grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(10) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength() }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(20) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(230) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(220) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(250, GridUnitType.Star) }); StackPanel leftSP = new StackPanel(); leftSP.Margin = new Thickness(5, 0, 30, 0); leftSP.SetValue(Grid.RowProperty, 1); leftSP.SetValue(Grid.ColumnProperty, 1); StackPanel middleSP = new StackPanel(); middleSP.Margin = new Thickness(30, 0, 30, 0); middleSP.SetValue(Grid.RowProperty, 1); middleSP.SetValue(Grid.ColumnProperty, 2); StackPanel rightSP = new StackPanel(); rightSP.Margin = new Thickness(30, 0, 0, 0); rightSP.SetValue(Grid.RowProperty, 1); rightSP.SetValue(Grid.ColumnProperty, 3); grid.Children.Add(leftSP); grid.Children.Add(middleSP); grid.Children.Add(rightSP); for (int i = 0; i < prompts.Count(); i++) { var prompt = prompts[i]; if (prompt.ControlType == ControlType.TextBox || prompt.ControlType == ControlType.UnEditabledTextBox || prompt.ControlType == ControlType.Invisabled) { Label label = new Label(); label.Foreground = getBrushById(prompt.ColorIndex); label.DataContext = prompt; label.SetBinding(Label.ContentProperty, new Binding("Name")); label.SetBinding(Label.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); label.SetBinding(Label.ToolTipProperty, new Binding("HelpMessage")); leftSP.Children.Add(label); TextBox tb = new TextBox(); //tb.MouseDoubleClick += tb_MouseDoubleClick; tb.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true); tb.DataContext = prompt; tb.SetBinding(TextBox.TextProperty, new Binding("PromptValue") { ValidatesOnExceptions = true, ValidatesOnDataErrors = true, NotifyOnValidationError = true }); tb.SetBinding(TextBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); tb.SetBinding(TextBox.IsEnabledProperty, new Binding("IsEnabled")); tb.SetBinding(TextBox.ToolTipProperty, new Binding("HelpMessage")); leftSP.Children.Add(tb); TextBlock error = new TextBlock(); error.Foreground = Brushes.Red; error.DataContext = prompt; error.SetBinding(TextBlock.TextProperty, new Binding("ErrorMessage")); error.SetBinding(Label.VisibilityProperty, new Binding("ErrorMessage") { Converter = new PromptValueToVisibilityConverter() }); leftSP.Children.Add(error); } else if (prompt.ControlType == ControlType.CheckBox) { CheckBox cb = new CheckBox(); cb.Foreground = getBrushById(prompt.ColorIndex); cb.Margin = new Thickness(0, 3, 0, 3); cb.DataContext = prompt; cb.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true); cb.SetBinding(CheckBox.IsCheckedProperty, new Binding("PromptValue") { Converter = new PromptValueToCheckedConverter() }); cb.SetBinding(CheckBox.ContentProperty, new Binding("Name")); cb.SetBinding(CheckBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); cb.SetBinding(CheckBox.ToolTipProperty, new Binding("HelpMessage")); rightSP.Children.Add(cb); } else if (prompt.ControlType == ControlType.ComboBox) { Label label = new Label(); label.Foreground = getBrushById(prompt.ColorIndex); label.DataContext = prompt; label.SetBinding(Label.ContentProperty, new Binding("Name")); label.SetBinding(Label.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); label.SetBinding(Label.ToolTipProperty, new Binding("HelpMessage")); leftSP.Children.Add(label); ComboBox combo = new ComboBox(); combo.Foreground = getBrushById(prompt.ColorIndex); combo.DataContext = prompt; combo.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true); combo.SetBinding(ComboBox.SelectedValueProperty, new Binding("PromptValue") { Converter = new PromptValueToIntConverter() }); combo.SetBinding(ComboBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); combo.SetBinding(ComboBox.ToolTipProperty, new Binding("HelpMessage")); combo.ItemsSource = prompt.ComboBoxItemsString.Split('|'); //DataTemplate dt = new DataTemplate(); //dt.DataType = typeof(string); //FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(TextBlock)); leftSP.Children.Add(combo); } else if (prompt.ControlType == ControlType.RadioButton) { GroupBox gb = new GroupBox(); gb.Foreground = getBrushById(prompt.ColorIndex); gb.DataContext = prompt; gb.SetBinding(GroupBox.HeaderProperty, new Binding("Tip")); gb.SetBinding(GroupBox.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); middleSP.Children.Add(gb); StackPanel spinsder = new StackPanel(); gb.Content = spinsder; RadioButton rb = new RadioButton(); rb.Foreground = getBrushById(prompt.ColorIndex); rb.Margin = new Thickness(0, 5, 0, 5); rb.DataContext = prompt; rb.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true); rb.SetBinding(RadioButton.ContentProperty, new Binding("Name")); rb.SetBinding(RadioButton.IsCheckedProperty, new Binding("PromptValue") { Converter = new PromptValueToCheckedConverter() }); rb.SetBinding(RadioButton.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); spinsder.Children.Add(rb); for (int x = i + 1; x < prompts.Count; x++) { var nextPrompt = prompts[x]; if (nextPrompt.ControlType != ControlType.OtherRadioButton) { break; } RadioButton rb2 = new RadioButton(); rb2.Foreground = getBrushById(prompt.ColorIndex); rb2.Margin = new Thickness(0, 5, 0, 5); rb2.DataContext = nextPrompt; rb2.AddHandler(UIElement.MouseEnterEvent, new RoutedEventHandler(tb_MouseLeftButtonDown), true); rb2.SetBinding(RadioButton.ContentProperty, new Binding("Name")); rb2.SetBinding(RadioButton.IsCheckedProperty, new Binding("PromptValue") { Converter = new PromptValueToCheckedConverter() }); rb2.SetBinding(RadioButton.VisibilityProperty, new Binding("Visible") { Converter = new PromptValueToVisibilityConverter() }); spinsder.Children.Add(rb2); } } } }
public static void OnPlaceholderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is PasswordBox) { PasswordBox txt = d as PasswordBox; if (txt == null || e.NewValue.ToString().Trim().Length == 0) { return; } RoutedEventHandler loadHandler = null; loadHandler = (s1, e1) => { txt.Loaded -= loadHandler; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } if (txt.Password.Length == 0) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } }; txt.Loaded += loadHandler; txt.PasswordChanged += (s1, e1) => { bool isShow = txt.Password.Length == 0; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } else { Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } } }; } else if (d is TextBox) { TextBox txt = d as TextBox; if (txt == null || e.NewValue.ToString().Trim().Length == 0) { return; } RoutedEventHandler loadHandler = null; loadHandler = (s1, e1) => { var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } else { txt.Loaded -= loadHandler; } Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } if (txt.Text.Length == 0) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } }; txt.Loaded += loadHandler; txt.TextChanged += (s1, e1) => { bool isShow = txt.Text.Length == 0; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } else { Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } } }; } else if (d is ComboBox) { ComboBox txt = d as ComboBox; if (txt == null || e.NewValue.ToString().Trim().Length == 0) { return; } RoutedEventHandler loadHandler = null; loadHandler = (s1, e1) => { txt.Loaded -= loadHandler; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } if (txt.Text == null || txt.Text.Length == 0) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } }; txt.Loaded += loadHandler; RoutedEventHandler textChangedHandler = (s1, e1) => { bool isShow = txt.Text != null && txt.Text.Length == 0; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } else { Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } } }; txt.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, textChangedHandler); } else if (d is RichTextBox) { RichTextBox txt = d as RichTextBox; if (e.NewValue == null) { return; } if (txt == null || e.NewValue.ToString().Trim().Length == 0) { return; } RoutedEventHandler loadHandler = null; loadHandler = (s1, e1) => { txt.Loaded -= loadHandler; var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } TextRange textRange = new TextRange(txt.Document.ContentStart, txt.Document.ContentEnd); if (txt.Document == null || string.IsNullOrWhiteSpace(textRange.Text)) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } }; txt.Loaded += loadHandler; RoutedEventHandler textChangedHandler = (s1, e1) => { // bool isShow = txt.Document != null && txt.Document.Blocks.Count == 0; TextRange textRange = new TextRange(txt.Document.ContentStart, txt.Document.ContentEnd); bool isShow = string.IsNullOrWhiteSpace(textRange.Text); var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } else { Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } } }; txt.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.TextChangedEvent, textChangedHandler); RoutedEventHandler getFocusedChangedHandler = (s1, e1) => { // bool isShow = txt.Document != null && txt.Document.Blocks.Count == 0; TextRange textRange = new TextRange(txt.Document.ContentStart, txt.Document.ContentEnd); bool isShow = string.IsNullOrWhiteSpace(textRange.Text); var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { Adorner[] ar = lay.GetAdorners(txt); if (ar != null) { for (int i = 0; i < ar.Length; i++) { if (ar[i] is PlaceholderAdorner) { lay.Remove(ar[i]); } } } } }; txt.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.GotFocusEvent, getFocusedChangedHandler); RoutedEventHandler lostFocusedChangedHandler = (s1, e1) => { // bool isShow = txt.Document != null && txt.Document.Blocks.Count == 0; TextRange textRange = new TextRange(txt.Document.ContentStart, txt.Document.ContentEnd); bool isShow = string.IsNullOrWhiteSpace(textRange.Text); var lay = AdornerLayer.GetAdornerLayer(txt); if (lay == null) { return; } if (isShow) { lay.Add(new PlaceholderAdorner(txt, e.NewValue.ToString())); } }; txt.AddHandler(System.Windows.Controls.Primitives.TextBoxBase.LostFocusEvent, lostFocusedChangedHandler); } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); LevelBars = new LevelBar[4]; LevelBars[0] = Template.FindName("SensorBar1", this) as LevelBar; LevelBars[1] = Template.FindName("SensorBar2", this) as LevelBar; LevelBars[2] = Template.FindName("SensorBar3", this) as LevelBar; LevelBars[3] = Template.FindName("SensorBar4", this) as LevelBar; LevelBarText = new Label[4]; LevelBarText[0] = Template.FindName("SensorBarLevel1", this) as Label; LevelBarText[1] = Template.FindName("SensorBarLevel2", this) as Label; LevelBarText[2] = Template.FindName("SensorBarLevel3", this) as Label; LevelBarText[3] = Template.FindName("SensorBarLevel4", this) as Label; DiagnosticMode = Template.FindName("DiagnosticMode", this) as ComboBox; CurrentDIP = Template.FindName("CurrentDIP", this) as FrameImage; ExpectedDIP = Template.FindName("ExpectedDIP", this) as FrameImage; NoResponseFromPanel = Template.FindName("NoResponseFromPanel", this) as FrameworkElement; NoResponseFromSensors = Template.FindName("NoResponseFromSensors", this) as FrameworkElement; P1Diagnostics = Template.FindName("P1Diagnostics", this) as FrameworkElement; P2Diagnostics = Template.FindName("P2Diagnostics", this) as FrameworkElement; // Only show the mode dropdown in debug mode. In regular use, just show calibrated values. DiagnosticMode.Visibility = Helpers.GetDebug()? Visibility.Visible:Visibility.Collapsed; Button Recalibrate = Template.FindName("Recalibrate", this) as Button; Recalibrate.Click += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.ForceRecalibration(pad); } }; Button LightAll = Template.FindName("LightAll", this) as Button; LightAll.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { SetShowAllLights?.Invoke(true); }; LightAll.PreviewMouseUp += delegate(object sender, MouseButtonEventArgs e) { SetShowAllLights?.Invoke(false); }; // Update the test mode when the dropdown is changed. DiagnosticMode.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetTestMode(pad, GetTestMode()); } })); OnConfigChange onConfigChange; onConfigChange = new OnConfigChange(this, delegate(LoadFromConfigDelegateArgs args) { Refresh(args); }); onConfigChange.RefreshOnTestDataChange = true; Loaded += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetTestMode(pad, GetTestMode()); } }; Unloaded += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetTestMode(pad, SMX.SMX.SensorTestMode.Off); } }; }
public LiveSimulation(Circuit.Schematic Simulate, Audio.Device Device, Audio.Channel[] Inputs, Audio.Channel[] Outputs) { try { InitializeComponent(); // Make a clone of the schematic so we can mess with it. Circuit.Schematic clone = Circuit.Schematic.Deserialize(Simulate.Serialize(), Log); clone.Elements.ItemAdded += OnElementAdded; clone.Elements.ItemRemoved += OnElementRemoved; Schematic = new SimulationSchematic(clone); Schematic.SelectionChanged += OnProbeSelected; // Build the circuit from the schematic. circuit = Schematic.Schematic.Build(Log); // Create the input and output controls. IEnumerable <Circuit.Component> components = circuit.Components; // Create audio input channels. for (int i = 0; i < Inputs.Length; ++i) { InputChannels.Add(new InputChannel(i) { Name = Inputs[i].Name }); } ComputerAlgebra.Expression speakers = 0; foreach (Circuit.Component i in components) { Circuit.Symbol S = i.Tag as Circuit.Symbol; if (S == null) { continue; } SymbolControl tag = (SymbolControl)S.Tag; if (tag == null) { continue; } // Create potentiometers. Circuit.IPotControl c = i as Circuit.IPotControl; if (c != null) { PotControl pot = new PotControl() { Width = 80, Height = 80, Opacity = 0.5, FontSize = 15, FontWeight = FontWeights.Bold, }; Schematic.overlays.Children.Add(pot); Canvas.SetLeft(pot, Canvas.GetLeft(tag) - pot.Width / 2 + tag.Width / 2); Canvas.SetTop(pot, Canvas.GetTop(tag) - pot.Height / 2 + tag.Height / 2); pot.Value = c.PotValue; pot.ValueChanged += x => { c.PotValue = x; UpdateSimulation(false); }; pot.MouseEnter += (o, e) => pot.Opacity = 0.95; pot.MouseLeave += (o, e) => pot.Opacity = 0.5; } // Create Buttons. Circuit.IButtonControl b = i as Circuit.IButtonControl; if (b != null) { Button button = new Button() { Width = tag.Width, Height = tag.Height, Opacity = 0.5, Background = Brushes.White, }; Schematic.overlays.Children.Add(button); Canvas.SetLeft(button, Canvas.GetLeft(tag)); Canvas.SetTop(button, Canvas.GetTop(tag)); button.Click += (o, e) => { // Click all the buttons in the group. foreach (Circuit.IButtonControl j in components.OfType <Circuit.IButtonControl>().Where(x => x.Group == b.Group)) { j.Click(); } UpdateSimulation(true); }; button.MouseEnter += (o, e) => button.Opacity = 0.95; button.MouseLeave += (o, e) => button.Opacity = 0.5; } Circuit.Speaker output = i as Circuit.Speaker; if (output != null) { speakers += output.V; } // Create input controls. Circuit.Input input = i as Circuit.Input; if (input != null) { tag.ShowText = false; ComboBox combo = new ComboBox() { Width = 80, Height = 24, Opacity = 0.5, IsEditable = true, SelectedValuePath = "Tag", }; foreach (InputChannel j in InputChannels) { combo.Items.Add(new ComboBoxItem() { Tag = j, Content = j.Name }); } Schematic.overlays.Children.Add(combo); Canvas.SetLeft(combo, Canvas.GetLeft(tag) - combo.Width / 2 + tag.Width / 2); Canvas.SetTop(combo, Canvas.GetTop(tag) - combo.Height / 2 + tag.Height / 2); ComputerAlgebra.Expression V = Circuit.Component.DependentVariable(input.Name, Circuit.Component.t); inputs[V] = new SignalChannel(0); combo.SelectionChanged += (o, e) => { if (combo.SelectedItem != null) { ComboBoxItem it = (ComboBoxItem)combo.SelectedItem; inputs[V] = new InputChannel(((InputChannel)it.Tag).Index); } }; combo.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler((o, e) => { try { inputs[V] = new SignalChannel(Circuit.Quantity.Parse(combo.Text, Circuit.Units.V)); } catch (Exception) { // If there is an error in the expression, zero out the signal. inputs[V] = new SignalChannel(0); } })); if (combo.Items.Count > 0) { combo.SelectedItem = combo.Items[0]; } else { combo.Text = "0 V"; } combo.MouseEnter += (o, e) => combo.Opacity = 0.95; combo.MouseLeave += (o, e) => combo.Opacity = 0.5; } } // Create audio output channels. for (int i = 0; i < Outputs.Length; ++i) { OutputChannel c = new OutputChannel(i) { Name = Outputs[i].Name, Signal = speakers }; c.PropertyChanged += (o, e) => { if (e.PropertyName == "Signal") { RebuildSolution(); } }; OutputChannels.Add(c); } // Begin audio processing. if (Inputs.Any() || Outputs.Any()) { stream = Device.Open(ProcessSamples, Inputs, Outputs); } else { stream = new NullStream(ProcessSamples); } ContentRendered += (o, e) => RebuildSolution(); Closed += (s, e) => stream.Stop(); } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Responsible for generating both modal and non modal /// enumerated UI components. /// </summary> /// <param name="agg"></param> /// <returns></returns> private UIElement genEnumerationSelector(Aggregate agg) { //gen base ui elements. StackPanel stk = new StackPanel(); ComboBox cbx = new ComboBox(); UniformGrid grd = new UniformGrid(); Label lbl = new Label(); lbl.Content = agg.name; //determine the nature of modallity. bool modal = true; for (int i = 0; i < agg.aggregation.Count; i++) { //why is the C# for iterator const? Its annoying... var item = agg.aggregation[i]; //mutal exclusion in this case means all other options should be //deselected if this one is choosen. i.e. AllFlags and NoFlags //are a direct contradiction. //modality is whether ALL options are mutually exclusive. if (item.name == "AllFlags") { modal = false; item.isMutuallyExclusive = true; } else if (item.name == "NoFlags") { item.isMutuallyExclusive = true; } } //add to compositor. stk.Children.Add(lbl); //deal with modality. if (modal) { //for modal, generate a list of mutually exclusive //options, i.e only one may be set. foreach (var item in agg.aggregation) { cbx.Items.Add(item.name); } //add to compositor. stk.Children.Add(cbx); //generate event aggregate mappings, and event callbacks. mUIToAggregation.Add(cbx, agg); cbx.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(onSingleSelect)); //select default. cbx.SelectedIndex = 0; } else { List <ToggleButton> tbnList = new List <ToggleButton>(); foreach (var item in agg.aggregation) { ToggleButton btn = new ToggleButton(); btn.Content = item.name; grd.Children.Add(btn); tbnList.Add(btn); //generate event aggregate mappings, and event callbacks. //(this is per button) mUIToAggregation.Add(btn, agg); btn.AddHandler(Button.ClickEvent, new RoutedEventHandler(onMultiSelect)); } //select default. tbnList[0].IsChecked = true; stk.Children.Add(grd); } return(stk); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); LevelBars = new LevelBar[4]; LevelBars[0] = Template.FindName("SensorBar1", this) as LevelBar; LevelBars[1] = Template.FindName("SensorBar2", this) as LevelBar; LevelBars[2] = Template.FindName("SensorBar3", this) as LevelBar; LevelBars[3] = Template.FindName("SensorBar4", this) as LevelBar; LevelBarText = new Label[4]; LevelBarText[0] = Template.FindName("SensorBarLevel1", this) as Label; LevelBarText[1] = Template.FindName("SensorBarLevel2", this) as Label; LevelBarText[2] = Template.FindName("SensorBarLevel3", this) as Label; LevelBarText[3] = Template.FindName("SensorBarLevel4", this) as Label; DiagnosticMode = Template.FindName("DiagnosticMode", this) as ComboBox; CurrentDIPGroup = Template.FindName("CurrentDIPGroup", this) as Panel; CurrentDIP = Template.FindName("CurrentDIP", this) as FrameImage; ExpectedDIP = Template.FindName("ExpectedDIP", this) as FrameImage; NoResponseFromPanel = Template.FindName("NoResponseFromPanel", this) as FrameworkElement; NoResponseFromSensors = Template.FindName("NoResponseFromSensors", this) as FrameworkElement; BadSensorDIPSwitches = Template.FindName("BadSensorDIPSwitches", this) as FrameworkElement; P1Diagnostics = Template.FindName("P1Diagnostics", this) as FrameworkElement; P2Diagnostics = Template.FindName("P2Diagnostics", this) as FrameworkElement; DIPLabelRight = Template.FindName("DIPLabelRight", this) as FrameworkElement; DIPLabelLeft = Template.FindName("DIPLabelLeft", this) as FrameworkElement; Button Recalibrate = Template.FindName("Recalibrate", this) as Button; Recalibrate.Click += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.ForceRecalibration(pad); } }; // Note that we won't get a MouseUp if the display is hidden due to a controller // disconnection while the mouse is held. We handle this in Refresh(). Button LightAll = Template.FindName("LightAll", this) as Button; LightAll.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { SetShowAllLights?.Invoke(true); }; LightAll.PreviewMouseUp += delegate(object sender, MouseButtonEventArgs e) { SetShowAllLights?.Invoke(false); }; // Update the test mode when the dropdown is changed. DiagnosticMode.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetSensorTestMode(pad, GetTestMode()); } })); OnConfigChange onConfigChange; onConfigChange = new OnConfigChange(this, delegate(LoadFromConfigDelegateArgs args) { Refresh(args); }); onConfigChange.RefreshOnTestDataChange = true; Loaded += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetSensorTestMode(pad, GetTestMode()); } }; Unloaded += delegate(object sender, RoutedEventArgs e) { for (int pad = 0; pad < 2; ++pad) { SMX.SMX.SetSensorTestMode(pad, SMX.SMX.SensorTestMode.Off); } }; }
public LiveSimulation(Schematic Simulate, Audio.Device Device, Audio.Channel[] Inputs, Audio.Channel[] Outputs) { try { InitializeComponent(); // Make a clone of the schematic so we can mess with it. var clone = Circuit.Schematic.Deserialize(Simulate.Serialize(), Log); clone.Elements.ItemAdded += OnElementAdded; clone.Elements.ItemRemoved += OnElementRemoved; Schematic = new SimulationSchematic(clone); Schematic.SelectionChanged += OnProbeSelected; // Build the circuit from the schematic. circuit = Schematic.Schematic.Build(Log); // Create the input and output controls. IEnumerable <Circuit.Component> components = circuit.Components; // Create audio input channels. for (int i = 0; i < Inputs.Length; ++i) { InputChannels.Add(new InputChannel(i) { Name = Inputs[i].Name }); } ComputerAlgebra.Expression speakers = 0; foreach (Circuit.Component i in components) { Symbol S = i.Tag as Symbol; if (S == null) { continue; } SymbolControl tag = (SymbolControl)S.Tag; if (tag == null) { continue; } // Create potentiometers. if (i is IPotControl potentiometer) { var potControl = new PotControl() { Width = 80, Height = 80, Opacity = 0.5, FontSize = 15, FontWeight = FontWeights.Bold, }; Schematic.Overlays.Children.Add(potControl); Canvas.SetLeft(potControl, Canvas.GetLeft(tag) - potControl.Width / 2 + tag.Width / 2); Canvas.SetTop(potControl, Canvas.GetTop(tag) - potControl.Height / 2 + tag.Height / 2); var binding = new Binding { Source = potentiometer, Path = new PropertyPath("(0)", typeof(IPotControl).GetProperty(nameof(IPotControl.PotValue))), Mode = BindingMode.TwoWay, NotifyOnSourceUpdated = true }; potControl.SetBinding(PotControl.ValueProperty, binding); potControl.AddHandler(Binding.SourceUpdatedEvent, new RoutedEventHandler((o, args) => { if (!string.IsNullOrEmpty(potentiometer.Group)) { foreach (var p in components.OfType <IPotControl>().Where(p => p != potentiometer && p.Group == potentiometer.Group)) { p.PotValue = (o as PotControl).Value; } } UpdateSimulation(false); })); potControl.MouseEnter += (o, e) => potControl.Opacity = 0.95; potControl.MouseLeave += (o, e) => potControl.Opacity = 0.5; } // Create Buttons. if (i is IButtonControl b) { Button button = new Button() { Width = tag.Width, Height = tag.Height, Opacity = 0.5, Background = Brushes.White, }; Schematic.Overlays.Children.Add(button); Canvas.SetLeft(button, Canvas.GetLeft(tag)); Canvas.SetTop(button, Canvas.GetTop(tag)); button.Click += (o, e) => { b.Click(); // Click all the buttons in the group. if (!string.IsNullOrEmpty(b.Group)) { foreach (var j in components.OfType <IButtonControl>().Where(x => x != b && x.Group == b.Group)) { j.Click(); } } UpdateSimulation(true); }; button.MouseEnter += (o, e) => button.Opacity = 0.95; button.MouseLeave += (o, e) => button.Opacity = 0.5; } if (i is Speaker output) { speakers += output.Out; } // Create input controls. if (i is Input input) { tag.ShowText = false; ComboBox combo = new ComboBox() { Width = 80, Height = 24, Opacity = 0.5, IsEditable = true, SelectedValuePath = "Tag", }; foreach (InputChannel j in InputChannels) { combo.Items.Add(new ComboBoxItem() { Tag = j, Content = j.Name }); } Schematic.Overlays.Children.Add(combo); Canvas.SetLeft(combo, Canvas.GetLeft(tag) - combo.Width / 2 + tag.Width / 2); Canvas.SetTop(combo, Canvas.GetTop(tag) - combo.Height / 2 + tag.Height / 2); ComputerAlgebra.Expression In = input.In; inputs[In] = new SignalChannel(0); combo.SelectionChanged += (o, e) => { if (combo.SelectedItem != null) { ComboBoxItem it = (ComboBoxItem)combo.SelectedItem; inputs[In] = new InputChannel(((InputChannel)it.Tag).Index); } }; combo.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler((o, e) => { try { inputs[In] = new SignalChannel(ComputerAlgebra.Expression.Parse(combo.Text)); } catch (Exception) { // If there is an error in the expression, zero out the signal. inputs[In] = new SignalChannel(0); } })); if (combo.Items.Count > 0) { combo.SelectedItem = combo.Items[0]; } else { combo.Text = "0 V"; } combo.MouseEnter += (o, e) => combo.Opacity = 0.95; combo.MouseLeave += (o, e) => combo.Opacity = 0.5; } } // Create audio output channels. for (int i = 0; i < Outputs.Length; ++i) { OutputChannel c = new OutputChannel(i) { Name = Outputs[i].Name, Signal = speakers }; c.PropertyChanged += (o, e) => { if (e.PropertyName == "Signal") { RebuildSolution(); } }; OutputChannels.Add(c); } // Begin audio processing. if (Inputs.Any() || Outputs.Any()) { stream = Device.Open(ProcessSamples, Inputs, Outputs); } else { stream = new NullStream(ProcessSamples); } ContentRendered += (o, e) => RebuildSolution(); Closed += (s, e) => stream.Stop(); timer = new System.Timers.Timer() { Interval = 100, AutoReset = true, Enabled = true, }; timer.Elapsed += timer_Elapsed; timer.Start(); } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
// Setting panel for Transposition Algorithm #region TRANSPOSITION_ALG_INTERFACE private void TranspositionDraw(ref StackPanel sP, int panel) { switch (panel) { case 0: int bytesPerPixel = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource); if (Encryption.algParams[0] == 0) { var generateAllBtn = new Button() { Style = Resources["GenerateButton"] as Style, Margin = new Thickness(0, 5, 0, 0), Width = 240, Content = "Згенерувати все", Name = "allRng", Uid = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource).ToString() }; generateAllBtn.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng)); sP.Children.Add(generateAllBtn); } List <WrapPanel> wPs = new List <WrapPanel>(); List <Brush> colors = new List <Brush>(); List <string> genLabels = new List <string>(); if (bytesPerPixel == 1) { wPs.Add(new WrapPanel()); colors.Add((SolidColorBrush) new BrushConverter().ConvertFrom("#BDBDBD")); genLabels.Add("Gray"); } else { wPs.AddRange(new[] { new WrapPanel(), new WrapPanel(), new WrapPanel() }); colors.AddRange(new[] { (SolidColorBrush) new BrushConverter().ConvertFrom("#f44336"), (SolidColorBrush) new BrushConverter().ConvertFrom("#4CAF50"), (SolidColorBrush) new BrushConverter().ConvertFrom("#2196F3") }); genLabels.AddRange(new[] { "Red", "Green", "Blue" }); } int color = 0; foreach (WrapPanel wP in wPs) { wP.Style = Resources["WrapPanel"] as Style; wP.Margin = new Thickness(0, 10, 0, 0); var colorRect = new Rectangle() { Style = Resources["ColorRectangle"] as Style, Fill = colors[color] }; wP.Children.Add(colorRect); if (Encryption.algParams[3] == 1) { dynamic generateField; if (Encryption.algParams[0] == 0) { generateField = new Button() { Style = Resources["GenerateButton"] as Style, Width = 347, Margin = new Thickness(5, 0, 0, 0), Content = "Генерація для " + genLabels[color], Name = genLabels[color] + "Rng", Uid = "0" }; generateField.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng)); } else { generateField = new PasswordBox() { Style = Resources["MainPasswordBox"] as Style, Width = 347, Margin = new Thickness(5, 0, 0, 0), Name = genLabels[color] + "Pass", Uid = "0" }; generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass)); } wP.Children.Add(generateField); } else { string[] labels = new string[] { "Генерація для рядків", "Генерація для стовпців" }; for (int i = 0; i < labels.Length; i++) { dynamic generateField; if (Encryption.algParams[0] == 0) { generateField = new Button() { Style = Resources["GenerateButton"] as Style, Margin = new Thickness(5, 0, 0, 0), Width = 171, Content = labels[i], Name = genLabels[color] + "Rng", Uid = i.ToString() }; generateField.AddHandler(Button.ClickEvent, new RoutedEventHandler(GenerateRng)); } else { generateField = new PasswordBox() { Style = Resources["MainPasswordBox"] as Style, Margin = new Thickness(5, 0, 0, 0), Width = 171, Name = genLabels[color] + "Pass", Uid = i.ToString() }; generateField.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(GeneratePass)); } wP.Children.Add(generateField); } } sP.Children.Add(wP); color++; } break; case 1: sP.Margin = new Thickness(20, 0, 0, 0); var rngType = new RadioButton() { Width = 330, Style = Resources["MainRadioButton"] as Style, Margin = new Thickness(0, 5, 0, 0), GroupName = "keyType", IsChecked = Encryption.algParams[0] == 0 ? true : false }; rngType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypeRng)); var rngTypeText = new TextBlock() { Style = Resources["TextBlock"] as Style, Text = "Ключ з криптографічного генератора псевдовипадкових послідовностей", }; var passType = new RadioButton() { Width = 330, Style = Resources["MainRadioButton"] as Style, Margin = new Thickness(0, 10, 0, 10), GroupName = "keyType", IsChecked = Encryption.algParams[0] == 1 ? true : false }; passType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(KeyTypePass)); var passTypeText = new TextBlock() { Style = Resources["TextBlock"] as Style, Text = "Ключ генерується розширенням паролю" }; var inBlocks = new CheckBox() { Style = Resources["MainCheckBox"] as Style, Content = "Перестановки в середині блока", Margin = new Thickness(0, 5, 0, 0), IsChecked = Encryption.algParams[1] == 1 ? true : false }; inBlocks.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(InBlockEncription)); rngType.Content = rngTypeText; passType.Content = passTypeText; sP.Children.Add(rngType); sP.Children.Add(passType); sP.Children.Add(inBlocks); break; case 2: sP.Margin = new Thickness(20, 0, 0, 0); var label = new Label() { Style = Resources["ParamLabel"] as Style, Content = "Розміри блока:" }; List <string> cBItems = new List <string>() { "256", "128", "64", "32", "16" }; var comboBox = new ComboBox() { Width = 100, Margin = new Thickness(5, 0, 0, 0), ItemsSource = cBItems, SelectedIndex = cBItems.IndexOf(Encryption.algParams[2].ToString()) }; comboBox.AddHandler(ComboBox.SelectionChangedEvent, new RoutedEventHandler(BlockSize)); var wPc = new WrapPanel(); wPc.Children.Add(label); wPc.Children.Add(comboBox); sP.Children.Add(wPc); var rowType = new RadioButton() { Style = Resources["MainRadioButton"] as Style, Margin = new Thickness(0, 5, 0, 0), GroupName = "chipherType", IsChecked = Encryption.algParams[3] == 1 ? true : false }; rowType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(ChipherType1D)); var rowTypeText = new TextBlock() { Style = Resources["TextBlock"] as Style, Text = "Режим одномірного шифрування" }; var colType = new RadioButton() { Style = Resources["MainRadioButton"] as Style, Margin = new Thickness(0, 10, 0, 10), GroupName = "chipherType", IsChecked = Encryption.algParams[3] == 2 ? true : false }; var colTypeText = new TextBlock() { Style = Resources["TextBlock"] as Style, Text = "Режим двомірного шифрування" }; colType.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(ChipherType2D)); rowType.Content = rowTypeText; colType.Content = colTypeText; sP.Children.Add(rowType); sP.Children.Add(colType); break; } }