private CheckBox CreateCheckBox(object source, string propertyName) { CheckBox checkBox = new CheckBox(); Binding bd = new System.Windows.Data.Binding(propertyName); bd.Mode = BindingMode.TwoWay; bd.Source = source; checkBox.SetBinding(CheckBox.IsCheckedProperty, bd); return checkBox; }
/// <summary> /// Creates a CheckBox for switch parameters /// </summary> /// <param name="parameterViewModel">DataContext object</param> /// <param name="rowNumber">Row number</param> /// <returns>a CheckBox for switch parameters</returns> private static CheckBox CreateCheckBox(ParameterViewModel parameterViewModel, int rowNumber) { CheckBox checkBox = new CheckBox(); checkBox.SetBinding(Label.ContentProperty, new Binding("NameCheckLabel")); checkBox.DataContext = parameterViewModel; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; checkBox.SetValue(Grid.ColumnProperty, 0); checkBox.SetValue(Grid.ColumnSpanProperty, 2); checkBox.SetValue(Grid.RowProperty, rowNumber); checkBox.IsThreeState = false; checkBox.Margin = new Thickness(8, rowNumber == 0 ? 7 : 5, 0, 5); checkBox.SetBinding(CheckBox.ToolTipProperty, new Binding("ToolTip")); Binding valueBinding = new Binding("Value"); checkBox.SetBinding(CheckBox.IsCheckedProperty, valueBinding); //// Add AutomationProperties.AutomationId for Ui Automation test. checkBox.SetValue( System.Windows.Automation.AutomationProperties.AutomationIdProperty, string.Format(CultureInfo.CurrentCulture, "chk{0}", parameterViewModel.Name)); checkBox.SetValue( System.Windows.Automation.AutomationProperties.NameProperty, parameterViewModel.Name); return checkBox; }
private StackPanel build_lblcb(string text, string property) { TextBlock tb = new TextBlock(); tb.Text = text; tb.TextAlignment = TextAlignment.Right; tb.VerticalAlignment = System.Windows.VerticalAlignment.Center; tb.Width = 55; StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; CheckBox cb = new CheckBox(); cb.VerticalAlignment = System.Windows.VerticalAlignment.Center; Binding bind = new Binding(property); cb.SetBinding(CheckBox.IsCheckedProperty, bind); SolidColorBrush mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = Color.FromArgb(255, 51, 51, 51); cb.Background = mySolidColorBrush; SolidColorBrush mySolidColorBrush2 = new SolidColorBrush(); mySolidColorBrush2.Color = Color.FromArgb(255, 112, 112, 112); cb.BorderBrush = mySolidColorBrush2; //Background="#FF333333" BorderBrush="#FF707070" sp.Height = 25; sp.Children.Add(tb); sp.Children.Add(cb); return sp; }
public FrameworkElement GetControl(WorkFlowViewElement viewElement, Context context) { var checkbox = new System.Windows.Controls.CheckBox() { Content = viewElement.Properties["Caption"].ToString(context), FontSize = viewElement.Properties["FontSize"].ToInt(context), }; viewElement.SetSize(checkbox, context); checkbox.DataContext = viewElement.Parent.Parent.Variables[viewElement.Properties["Variable"].ToString(context)]; checkbox.SetBinding(ToggleButton.IsCheckedProperty, "Value"); //if (viewElement.Properties["Style"].Value == "Rounded") //{ // checkbox.Style = Application.Current.Resources["MaterialDesignFloatingActionButton"] as Style; //} if (viewElement.Properties["BackgroundColor"].ToString(context) != "Transparent" && viewElement.Properties["BackgroundColor"].ToString(context) != "#00FFFFFF") { checkbox.Background = new SolidColorBrush( (Color)ColorConverter.ConvertFromString(viewElement.Properties["BackgroundColor"].ToString(context))); } if (viewElement.Properties["ForegroundColor"].ToString(context) != "Transparent" && viewElement.Properties["ForegroundColor"].ToString(context) != "#00FFFFFF") { checkbox.Foreground = new SolidColorBrush( (Color)ColorConverter.ConvertFromString(viewElement.Properties["ForegroundColor"].ToString(context))); } return(checkbox); }
private void ConfigureCheckBox(CheckBox checkBox) { checkBox.HorizontalAlignment = HorizontalAlignment.Center; checkBox.VerticalAlignment = VerticalAlignment.Center; checkBox.IsThreeState = this.IsThreeState; checkBox.SetBinding(CheckBox.IsCheckedProperty, this.Binding); }
private void PopulateScanningOptions() { foreach (var queryParameter in MainViewModel.RemoteParameterSet) { StackPanel parent = null; switch (queryParameter.Group) { case RemoteQueryGroups.Dns: parent = SpDns; break; case RemoteQueryGroups.Arp: parent = SpArp; break; case RemoteQueryGroups.NetBios: parent = SpNetBios; break; case RemoteQueryGroups.RemoteRegistry: parent = SpRemoteRegistry; break; case RemoteQueryGroups.Snmp: parent = SpSnmp; break; case RemoteQueryGroups.Wmi: parent = SpWmi; break; } var cb = new CheckBox { Content = queryParameter.Name, FocusVisualStyle = null }; cb.SetBinding(ToggleButton.IsCheckedProperty, new Binding { Source = queryParameter, Path = new PropertyPath("Enabled") }); parent?.Children.Add(cb); } }
public static void Add(Grid grid, string label, Binding value, int row, string labelStyle, string inputStyle, int startColumn) { int column = startColumn; if (label != "") { TextBlock labelElement = new TextBlock(); labelElement.Style = App.Instance.Resources[labelStyle] as Style; labelElement.SetResourceReference(TextBlock.TextProperty, label); labelElement.VerticalAlignment = VerticalAlignment.Center; labelElement.Margin = new Thickness(column > 0 ? 5 : 0, 0, 0, 5); grid.Children.Add(labelElement); Grid.SetColumn(labelElement, column); Grid.SetRow(labelElement, row); column += 1; } System.Windows.Controls.CheckBox inputElement = new System.Windows.Controls.CheckBox(); inputElement.HorizontalAlignment = HorizontalAlignment.Stretch; inputElement.Margin = new Thickness(column > 0 ? 5 : 0, 0, 0, 5); if (inputStyle != "") { Style s = App.Instance.Resources[inputStyle] as Style;; if (s.TargetType == typeof(System.Windows.Controls.CheckBox)) { inputElement.Style = s; } } inputElement.SetBinding(System.Windows.Controls.CheckBox.IsCheckedProperty, value); grid.Children.Add(inputElement); Grid.SetColumn(inputElement, column); Grid.SetRow(inputElement, row); }
public SimpleUIBoundToCustomer() { var stack = new StackPanel(); Content = stack; var textBlock = new TextBlock(); textBlock.SetBinding(TextBlock.TextProperty, new Binding("FirstName")); stack.Children.Add(textBlock); textBlock = new TextBlock(); textBlock.SetBinding(TextBlock.TextProperty, new Binding("LstName")); //purposefully misspelled stack.Children.Add(textBlock); textBlock = new TextBlock(); textBlock.SetBinding(TextBlock.TextProperty, new Binding()); //context stack.Children.Add(textBlock); var checkbox = new CheckBox(); checkbox.SetBinding(CheckBox.IsCheckedProperty, new Binding("asdfsdf")); //does not exist stack.Children.Add(checkbox); var tooltip = new ToolTip(); tooltip.SetBinding(System.Windows.Controls.ToolTip.ContentProperty, new Binding("asdfasdasdf")); // does not exist stack.ToolTip = tooltip; var childUserControl = new SimpleUIBoundToCustomerByAttachedPorperty(); stack.Children.Add(childUserControl); }
static void OnFlagTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { Type flagType = args.NewValue as Type; Fx.Assert(flagType == null || flagType.IsEnum, "FlagType should be null or enum"); Fx.Assert(flagType == null || Attribute.IsDefined(flagType, typeof(FlagsAttribute)), "FlagType should be null or have flags attribute"); if (flagType == null) { return; } int index = 0; FlagPanel panel = sender as FlagPanel; string[] flagNames = flagType.GetEnumNames(); string zeroValueString = Enum.ToObject(flagType, 0).ToString(); foreach (string flagName in flagNames) { if (zeroValueString.Equals("0") || !flagName.Equals(zeroValueString)) { CheckBox checkBox = new CheckBox(); panel.Children.Add(checkBox); checkBox.Content = flagName; checkBox.DataContext = panel; checkBox.SetValue(AutomationProperties.AutomationIdProperty, flagName); Binding binding = new Binding("FlagString"); binding.Mode = BindingMode.TwoWay; binding.Converter = new CheckBoxStringConverter(index); binding.ConverterParameter = panel; checkBox.SetBinding(CheckBox.IsCheckedProperty, binding); index++; } } }
protected void BindToOption(CheckBox checkBox, object source, string propertyName) { checkBox.SetBinding(ToggleButton.IsCheckedProperty, new System.Windows.Data.Binding { Source = source, Path = new PropertyPath(propertyName) }); }
public override FrameworkElement LoadUI(Option option) { if (_checkBox != null) return _checkBox; _checkBox = new CheckBox { DataContext = this, Content = _content ?? option.DisplayName }; _checkBox.SetBinding(ToggleButton.IsCheckedProperty, "CurrentValue"); return _checkBox; }
private void ConfigureCheckBox(CheckBox checkBox) { checkBox.HorizontalAlignment = HorizontalAlignment.Center; checkBox.VerticalAlignment = VerticalAlignment.Center; checkBox.IsThreeState = this.IsThreeState; if (this.Binding != null || !DesignerProperties.IsInDesignTool) { checkBox.SetBinding(this.BindingTarget, this.Binding); } }
private Control GenerateCheckBox(PropertyInfo property, Binding binding) { CheckBox checkBox = new CheckBox() { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(2, 4, 0, 4) }; checkBox.IsEnabled = (bindables[property.Name].Direction == BindingDirection.TwoWay); this.bindings.Add(property.Name, checkBox.SetBinding(CheckBox.IsCheckedProperty, binding)); return(checkBox); }
protected void BindToOption(CheckBox checkbox, PerLanguageOption<bool> optionKey, string languageName) { Binding binding = new Binding(); binding.Source = new PerLanguageOptionBinding<bool>(OptionService, optionKey, languageName); binding.Path = new PropertyPath("Value"); binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; var bindingExpression = checkbox.SetBinding(CheckBox.IsCheckedProperty, binding); _bindingExpressions.Add(bindingExpression); }
protected void BindToOption(CheckBox checkbox, Option<bool> optionKey) { var binding = new Binding() { Source = new OptionBinding<bool>(OptionService, optionKey), Path = new PropertyPath("Value"), UpdateSourceTrigger = UpdateSourceTrigger.Explicit }; var bindingExpression = checkbox.SetBinding(CheckBox.IsCheckedProperty, binding); _bindingExpressions.Add(bindingExpression); }
/// <summary> /// Generate content for cell by column binding /// </summary> /// <returns>Checkbox element</returns> internal override FrameworkElement GetGeneratedContent() { CheckBox result = new CheckBox(); if (this.Binding != null) { result.SetBinding(CheckBox.IsCheckedProperty, this.Binding); } result.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center); return result; }
private CheckBox CreateBoundCheckBox(string content, object source, string sourcePropertyName) { var cb = new CheckBox { Content = content }; var binding = new Binding() { Source = source, Path = new PropertyPath(sourcePropertyName) }; base.AddBinding(cb.SetBinding(CheckBox.IsCheckedProperty, binding)); return cb; }
public static void Display(DecompilerTextView textView) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.WriteLine(string.Format("dnSpy version {0}", currentVersion.ToString()), TextTokenType.Text); var decVer = typeof(ICSharpCode.Decompiler.Ast.AstBuilder).Assembly.GetName().Version; output.WriteLine(string.Format("ILSpy Decompiler version {0}.{1}.{2}", decVer.Major, decVer.Minor, decVer.Build), TextTokenType.Text); if (checkForUpdateCode) output.AddUIElement( delegate { StackPanel stackPanel = new StackPanel(); stackPanel.HorizontalAlignment = HorizontalAlignment.Center; stackPanel.Orientation = Orientation.Horizontal; if (latestAvailableVersion == null) { AddUpdateCheckButton(stackPanel, textView); } else { // we already retrieved the latest version sometime earlier ShowAvailableVersion(latestAvailableVersion, stackPanel); } CheckBox checkBox = new CheckBox(); checkBox.Margin = new Thickness(4); checkBox.Content = "Automatically check for updates every week"; UpdateSettings settings = new UpdateSettings(DNSpySettings.Load()); checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings }); return new StackPanel { Margin = new Thickness(0, 4, 0, 0), Cursor = Cursors.Arrow, Children = { stackPanel, checkBox } }; }); if (checkForUpdateCode) output.WriteLine(); foreach (var plugin in App.CompositionContainer.GetExportedValues<IAboutPageAddition>()) plugin.Write(output); output.WriteLine(); using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(dnSpy.StartUpClass), "README.txt")) { using (StreamReader r = new StreamReader(s)) { string line; while ((line = r.ReadLine()) != null) { output.WriteLine(line, TextTokenType.Text); } } } output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("COPYING", "resource:COPYING")); textView.ShowText(output); MainWindow.Instance.SetTitle(textView, "About"); }
public object CreateToolbarItem() { var checkBox = new CheckBox() { Content = new Image { Width = 16, Height = 16, Source = ImageCache.Instance.GetImage("PrivateInternal", BackgroundType.Toolbar), }, ToolTip = "Show Internal Types and Members", }; var binding = new Binding("FilterSettings.ShowInternalApi") { Source = MainWindow.Instance.SessionSettings, }; checkBox.SetBinding(CheckBox.IsCheckedProperty, binding); return checkBox; }
public static void Display(DecompilerTextView textView) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.WriteLine("ILSpy version " + RevisionClass.FullVersion); output.AddUIElement( delegate { StackPanel stackPanel = new StackPanel(); stackPanel.HorizontalAlignment = HorizontalAlignment.Center; stackPanel.Orientation = Orientation.Horizontal; if (latestAvailableVersion == null) { AddUpdateCheckButton(stackPanel, textView); } else { // we already retrieved the latest version sometime earlier ShowAvailableVersion(latestAvailableVersion, stackPanel); } CheckBox checkBox = new CheckBox(); checkBox.Margin = new Thickness(4); checkBox.Content = "Automatically check for updates every week"; UpdateSettings settings = new UpdateSettings(ILSpySettings.Load()); checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings }); return new StackPanel { Margin = new Thickness(0, 4, 0, 0), Cursor = Cursors.Arrow, Children = { stackPanel, checkBox } }; }); output.WriteLine(); foreach (var plugin in App.CompositionContainer.GetExportedValues<IAboutPageAddition>()) plugin.Write(output); output.WriteLine(); using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) { using (StreamReader r = new StreamReader(s)) { string line; while ((line = r.ReadLine()) != null) { output.WriteLine(line); } } } output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt")); textView.ShowText(output); //reset icon bar textView.manager.Bookmarks.Clear(); }
public object CreateToolbarItem() { var sp = new StackPanel { Orientation = Orientation.Horizontal, ToolTip = "Full Screen", }; sp.Children.Add(new Image { Width = 16, Height = 16, Source = ImageCache.Instance.GetImage("FullScreen", BackgroundType.ToolBarButtonChecked), }); sp.Children.Add(new TextBlock { Text = "Full Screen", Margin = new Thickness(5, 0, 0, 0), }); var checkBox = new CheckBox { Content = sp }; var binding = new Binding("IsFullScreen") { Source = MainWindow.Instance, }; checkBox.SetBinding(CheckBox.IsCheckedProperty, binding); return checkBox; }
private void RenderPrivileges(SecurityObject secObject, RadTabItem tabItem) { int rowHeight = 20; int rowIndex = 0; tabItem.Style = (Style)Application.Current.Resources["InnerTabItem"]; ScrollViewer sv = new ScrollViewer(); sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; //sv.Margin = new Thickness(3); sv.Background = (SolidColorBrush)Application.Current.Resources["PanelDarkBackground"]; sv.BorderBrush = (SolidColorBrush)Application.Current.Resources["PanelDarkBackground"]; Grid grid = new Grid(); grid.Background = (SolidColorBrush)Application.Current.Resources["PanelDarkBackground"]; sv.Content = grid; tabItem.Content = sv; foreach (var privilege in mPrivileges) { grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(rowHeight) }); CheckBox checkBox = new CheckBox(); grid.Children.Add(checkBox); checkBox.Content = privilege.Name; Grid.SetRow(checkBox, rowIndex); Grid.SetColumn(checkBox, 0); rowIndex++; RolePrivilegeViewModel rolePrivilegeViewModel; //Check set privileges var rolePrivilege = mRole.RolePrivileges.FirstOrDefault(x => x.SecObjectId == secObject.Id && x.PrivilegeId == privilege.Id); if (rolePrivilege != null) { rolePrivilegeViewModel = new RolePrivilegeViewModel(rolePrivilege); rolePrivilegeViewModel.HasAccess = true; } else { rolePrivilege = new RolePrivilege(); rolePrivilege.RoleId = mRoleId; rolePrivilege.SecObjectId = secObject.Id; rolePrivilege.PrivilegeId = privilege.Id; rolePrivilegeViewModel = new RolePrivilegeViewModel(rolePrivilege); rolePrivilegeViewModel.HasAccess = false; } mRolePrivilegesViewModel.Add(rolePrivilegeViewModel); //Bind System.Windows.Data.Binding checkBoxBinding = new System.Windows.Data.Binding("HasAccess"); checkBoxBinding.Mode = System.Windows.Data.BindingMode.TwoWay; checkBoxBinding.Source = rolePrivilegeViewModel; checkBox.SetBinding(CheckBox.IsCheckedProperty, checkBoxBinding); } }
/// <summary> /// The create element. /// </summary> /// <param name="cell"> /// The cell. /// </param> /// <param name="item"> /// The item. /// </param> /// <returns> /// </returns> protected virtual UIElement CreateElement(CellRef cell, object item = null) { FrameworkElement element = null; if (item == null) { item = this.GetItem(cell); } var cd = this.GetColumnDefinition(cell); if (cd != null && cd.DisplayTemplate != null) { element = new ContentControl { ContentTemplate = cd.DisplayTemplate, Content = item }; // note: vertical/horziontal alignment must be set in the DataTemplate } if (element == null) { var value = this.GetCellValue(cell); var type = value != null ? value.GetType() : null; var template = this.GetDisplayTemplate(type); if (template != null) { element = new ContentControl { ContentTemplate = template, Content = value }; } var binding = this.CreateBinding(cell, value); if (element == null && type == typeof(bool)) { var chkbox = new CheckBox { Cursor = Cursors.Arrow }; if (binding != null) { chkbox.SetBinding(ToggleButton.IsCheckedProperty, binding); } else { chkbox.IsChecked = (bool)value; chkbox.Checked += this.CellChecked; } element = chkbox; } if (element == null && typeof(BitmapSource).IsAssignableFrom(type)) { var chkbox = new Image { Source = (BitmapSource)value, Stretch = Stretch.None }; element = chkbox; } // if (element == null && typeof(Uri).IsAssignableFrom(type)) // { // element = new TextBlock(new Hyperlink(new Run(value != null ? value.ToString() : null)) { NavigateUri = (Uri)value }); // } if (element == null) { var textBlock = new TextBlock { Margin = new Thickness(4, 0, 4, 0), Foreground = this.Foreground }; if (binding != null) { textBlock.SetBinding(TextBlock.TextProperty, binding); } else { var formatString = this.GetFormatString(cell, value); var text = FormatValue(value, formatString); textBlock.Text = text; } element = textBlock; } element.Tag = type; if (binding != null) { element.DataContext = item; } element.VerticalAlignment = VerticalAlignment.Center; element.HorizontalAlignment = this.GetHorizontalAlignment(cell); } return element; }
void fill() { controlStack.Children.Clear(); foreach (PropertyInfo pi in type_.GetProperties()) { Label lbl = new Label { Content = pi.Name }; lbl.FontWeight = FontWeights.DemiBold; lbl.MinWidth = 120; StackPanel pnl = new StackPanel { Orientation = Orientation.Horizontal }; pnl.Margin = new Thickness(5); if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(float)) { TextBox tb = new TextBox(); tb.MinWidth = 240; tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name)); tb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } else if (pi.PropertyType == typeof(bool)) { CheckBox cb = new CheckBox(); cb.Content = pi.Name; Binding binding = new Binding(pi.Name); if (!pi.CanWrite) binding.Mode = BindingMode.OneWay; cb.SetBinding(CheckBox.IsCheckedProperty, binding); cb.Tag = pi; pnl.Children.Add(cb); controls_.Add(cb); } else if (pi.PropertyType == typeof(string)) { Urho.Resource res = pi.GetCustomAttribute<Urho.Resource>(); if (res != null) { ComboBox cb = new ComboBox(); if (res.Type == typeof(Urho.Material)) { cb.ItemsSource = UrhoPaths.inst().GetList(UrhoPaths.PATH_MATERIALS, false); } else if (res.Type == typeof(Urho.Shader)) { cb.ItemsSource = UrhoPaths.inst().GetList(UrhoPaths.PATH_SHADERS, false); } else if (res.Type == typeof(Urho.Technique)) { cb.ItemsSource = UrhoPaths.inst().GetList(UrhoPaths.PATH_TECHNIQUES, false); } else if (res.Type == typeof(Urho.BaseTexture) || res.Type == typeof(Urho.Texture)) { cb.ItemsSource = UrhoPaths.inst().GetList(UrhoPaths.PATH_TEXTURES, true); } cb.SetBinding(ComboBox.SelectedItemProperty, new Binding(pi.Name)); cb.MinWidth = 240; cb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(cb); controls_.Add(cb); } else { TextBox tb = new TextBox(); tb.MinWidth = 240; tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name)); tb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } } else if (pi.PropertyType == typeof(Urho.MinMax)) { MinMaxEditor tb = new MinMaxEditor(pi.Name); tb.Tag = pi; tb.SetBinding(MinMaxEditor.DataContextProperty, new Binding(pi.Name)); pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } else if (pi.PropertyType == typeof(Urho.Vector2)) { Vector2Editor tb = new Vector2Editor(pi.Name); tb.Tag = pi; tb.SetBinding(Vector2Editor.DataContextProperty, new Binding(pi.Name)); pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } else if (pi.PropertyType == typeof(Urho.Vector3)) { Vector3Editor tb = new Vector3Editor(pi.Name); tb.SetBinding(Vector3Editor.DataContextProperty, new Binding(pi.Name)); tb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } else if (pi.PropertyType == typeof(Urho.Vector4)) { Vector4Editor tb = new Vector4Editor(pi.Name); tb.SetBinding(Vector4Editor.DataContextProperty, new Binding(pi.Name)); tb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(tb); controls_.Add(tb); } else if (pi.PropertyType == typeof(Urho.UColor)) { //TODO show a color picker Xceed.Wpf.Toolkit.ColorPicker col = new Xceed.Wpf.Toolkit.ColorPicker(); Binding binding = new Binding(pi.Name); binding.Converter = new ColorToColorConverter(); col.SetBinding(Xceed.Wpf.Toolkit.ColorPicker.SelectedColorProperty, binding); col.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(col); controls_.Add(col); } else if (pi.PropertyType.IsEnum) { ComboBox cb = new ComboBox(); cb.ItemsSource = Enum.GetValues(pi.PropertyType); cb.SetBinding(ComboBox.SelectedItemProperty, new Binding(pi.Name)); cb.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(cb); controls_.Add(cb); } else { try { if (pi.PropertyType.GetGenericTypeDefinition() == typeof(ObservableCollection<>)) { //LIST GridEditor dg = new GridEditor(pi.PropertyType.GetGenericArguments()[0]); dg.Grid.SetBinding(DataGrid.ItemsSourceProperty, new Binding(pi.Name)); pnl.Children.Add(lbl); pnl.Children.Add(dg); controls_.Add(dg); } else { ReflectiveForm form = new ReflectiveForm(pi.PropertyType); form.Tag = pi; pnl.Children.Add(lbl); pnl.Children.Add(form); controls_.Add(form); } } catch (Exception ex) { ReflectiveForm form = new ReflectiveForm(pi.PropertyType); pnl.Children.Add(lbl); pnl.Children.Add(form); controls_.Add(form); } } controlStack.Children.Add(pnl); } }
private static ModelPropertyUiInfo CreateBooleanField(Grid parent, DisplayPropertyInfo property, String bindingPath, Style style, int row, int column) { Label labelElement = CreateLabel(property, row, column); var checkBox = new CheckBox { Name = "checkBox" + property.PropertyName, }; if (style != null) { checkBox.Style = style; } checkBox.VerticalAlignment = VerticalAlignment.Center; checkBox.SetBinding(ToggleButton.IsCheckedProperty, ModelUiCreatorHelper.CreateBinding(property, bindingPath)); if (property.IsReadOnly) { checkBox.IsEnabled = false; } Grid.SetRow(checkBox, row); Grid.SetColumn(checkBox, checked(column + 1)); parent.Children.Add(labelElement); parent.Children.Add(checkBox); // return ModelPropertyUiInfo elememtsInfo = new ModelPropertyUiInfo(property); elememtsInfo.Label = labelElement; elememtsInfo.Content = checkBox; return elememtsInfo; }
private void Preinit() { _toggleCheckBox = new CheckBox(); _toggleCheckBox.HorizontalAlignment = HorizontalAlignment.Center; _toggleCheckBox.VerticalAlignment = VerticalAlignment.Center; Binding checkBoxBinding = new Binding("toggle"); checkBoxBinding.Source = this; checkBoxBinding.Mode = BindingMode.TwoWay; checkBoxBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; _toggleCheckBox.SetBinding(CheckBox.IsCheckedProperty, checkBoxBinding); _topLabel = new Label(); _topLabel.HorizontalAlignment = HorizontalAlignment.Center; _topLabel.VerticalAlignment = VerticalAlignment.Center; _bottomLabel = new Label(); _bottomLabel.HorizontalAlignment = HorizontalAlignment.Center; _bottomLabel.VerticalAlignment = VerticalAlignment.Center; _leftLabel = new Label(); _leftLabel.HorizontalAlignment = HorizontalAlignment.Center; _leftLabel.VerticalAlignment = VerticalAlignment.Center; _rightLabel = new Label(); _rightLabel.HorizontalAlignment = HorizontalAlignment.Center; _rightLabel.VerticalAlignment = VerticalAlignment.Center; _graphMarkers = new ObservableCollection<GraphMarker>(); _graphMarkers.CollectionChanged += _graphMarkers_CollectionChanged; }
private static CheckBox CreateCheckBox(object obj, string propertyName) { CheckBox checkBox = new CheckBox(); checkBox.VerticalAlignment = System.Windows.VerticalAlignment.Center; checkBox.LayoutTransform = new ScaleTransform(CHECKBOX_SIZE, CHECKBOX_SIZE); Binding bd = new Binding(propertyName); bd.Source = obj; if (obj.GetType().GetProperty(propertyName).GetSetMethod(false) == null) { bd.Mode = BindingMode.OneWay; //checkBox.IsEnabled = false; } else { bd.Mode = BindingMode.TwoWay; } checkBox.SetBinding(CheckBox.IsCheckedProperty, bd); return checkBox; }
/// <summary> /// Creates the label control. /// </summary> /// <param name="pi">The property item.</param> /// <returns> /// An element. /// </returns> private FrameworkElement CreateLabel(PropertyItem pi) { FrameworkElement propertyLabel = null; if (pi.IsOptional) { var cb = new CheckBox { Content = pi.DisplayName, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0) }; cb.SetBinding( ToggleButton.IsCheckedProperty, pi.OptionalDescriptor != null ? new Binding(pi.OptionalDescriptor.Name) : new Binding(pi.Descriptor.Name) { Converter = NullToBoolConverter }); var g = new Grid(); g.Children.Add(cb); propertyLabel = g; } if (pi.IsEnabledByRadioButton) { var rb = new RadioButton { Content = pi.DisplayName, GroupName = pi.RadioDescriptor.Name, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0) }; var converter = new EnumToBooleanConverter(); converter.EnumType = pi.RadioDescriptor.PropertyType; rb.SetBinding( RadioButton.IsCheckedProperty, new Binding(pi.RadioDescriptor.Name) { Converter = converter, ConverterParameter = pi.RadioValue }); var g = new Grid(); g.Children.Add(rb); propertyLabel = g; } if (propertyLabel == null) { propertyLabel = new Label { Content = pi.DisplayName, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 4, 0, 0) }; } propertyLabel.Margin = new Thickness(0, 0, 4, 0); return propertyLabel; }
private void CreateOnOffStopOperationInfo(Grid grid, FALibrary.Part.FAPart part, string name, Action<object> OnAction, Action<object> OffAction, Action<object> StopAction, Func<bool> IsOn, Func<bool> IsOff, string onName, string offName) { GeneralOperationInfo obj = new GeneralOperationInfo(); RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(150, GridUnitType.Auto); rd.MinHeight = 100; grid.RowDefinitions.Add(rd); SetOperationGridColor(grid, grid.RowDefinitions.Count - 1); obj.Name = name; obj.On = OnAction; obj.Off = OffAction; obj.StatusOnName = onName; obj.StatusOffName = offName; obj.IsOn = IsOn; obj.IsOff = IsOff; Label labelName = new Label(); labelName.Height = Double.NaN; labelName.Width = Double.NaN; labelName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelName.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelName.Margin = new Thickness(2); Binding bd = new Binding("Name"); bd.Source = obj; bd.Mode = BindingMode.OneWay; TextBlock textBlockName = new TextBlock(); textBlockName.TextWrapping = TextWrapping.Wrap; textBlockName.TextAlignment = TextAlignment.Center; textBlockName.SetBinding(TextBlock.TextProperty, bd); labelName.Content = textBlockName; Label labelStatus = new Label(); labelStatus.Height = Double.NaN; labelStatus.Width = Double.NaN; labelStatus.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelStatus.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelStatus.Margin = new Thickness(2); bd = new Binding("Status"); bd.Source = obj; bd.Mode = BindingMode.OneWay; TextBlock textBlockStatus = new TextBlock(); textBlockStatus.TextWrapping = TextWrapping.Wrap; textBlockStatus.TextAlignment = TextAlignment.Center; textBlockStatus.SetBinding(TextBlock.TextProperty, bd); labelStatus.Content = textBlockStatus; Grid gridInputIOList = CreatePartInputIOList(part); Grid gridOutputIOList = CreatePartOutputIOList(part); Button buttonOnOff = new Button(); buttonOnOff.Height = Double.NaN; buttonOnOff.Width = Double.NaN; buttonOnOff.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; buttonOnOff.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; buttonOnOff.Margin = new Thickness(2); bd = new Binding("ButtonCaption"); bd.Source = obj; bd.Mode = BindingMode.OneWay; buttonOnOff.SetBinding(Button.ContentProperty, bd); buttonOnOff.Click += delegate(object sender, RoutedEventArgs e) { if (obj.IsOn()) OffAction(sender); else { if (obj.IsOff()) OnAction(sender); else if (StopAction != null) { StopAction(sender); } else OnAction(sender); } }; TextBox textBoxRepeat = new TextBox(); textBoxRepeat.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; textBoxRepeat.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; textBoxRepeat.Height = Double.NaN; textBoxRepeat.Width = Double.NaN; textBoxRepeat.Margin = new Thickness(2); bd = new Binding("RepeatTime"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; FAFramework.Utility.BindingUtility.SetBindingObject(textBoxRepeat, BindingMode.TwoWay, obj, TextBox.TextProperty, "RepeatTime"); CheckBox checkBoxRepeatUse = new CheckBox(); checkBoxRepeatUse.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBoxRepeatUse.VerticalAlignment = System.Windows.VerticalAlignment.Center; checkBoxRepeatUse.LayoutTransform = new ScaleTransform(CHECKBOX_SIZE, CHECKBOX_SIZE); bd = new Binding("RepeatUse"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; checkBoxRepeatUse.SetBinding(CheckBox.IsCheckedProperty, bd); int rowCount = grid.RowDefinitions.Count - 1; grid.Children.Add(labelName); Grid.SetColumn(labelName, 0); Grid.SetRow(labelName, rowCount); grid.Children.Add(labelStatus); Grid.SetColumn(labelStatus, 1); Grid.SetRow(labelStatus, rowCount); grid.Children.Add(gridInputIOList); Grid.SetColumn(gridInputIOList, 2); Grid.SetRow(gridInputIOList, rowCount); grid.Children.Add(gridOutputIOList); Grid.SetColumn(gridOutputIOList, 3); Grid.SetRow(gridOutputIOList, rowCount); grid.Children.Add(buttonOnOff); Grid.SetColumn(buttonOnOff, 4); Grid.SetRow(buttonOnOff, rowCount); grid.Children.Add(textBoxRepeat); Grid.SetColumn(textBoxRepeat, 5); Grid.SetRow(textBoxRepeat, rowCount); grid.Children.Add(checkBoxRepeatUse); Grid.SetColumn(checkBoxRepeatUse, 6); Grid.SetRow(checkBoxRepeatUse, rowCount); _ioOperationList.Add(obj); bd = new Binding("IsEnabledOutputIODirectControl"); bd.Source = this; bd.Mode = BindingMode.OneWay; gridOutputIOList.SetBinding(ListView.IsEnabledProperty, bd); }
private Grid CreatePartIOList(System.Collections.IList ioList) { Grid grid = new Grid(); if (ioList == null) return grid; grid.Width = double.NaN; grid.Height = double.NaN; //grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; //grid.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; grid.Margin = new Thickness(0, 0, 0, 0); int rowCount = 0; foreach (FALibrary.Part.MemoryBasePart.FAPartOutputIOInfo ioInfo in ioList) { RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(150, GridUnitType.Auto); grid.RowDefinitions.Add(rd); grid.VerticalAlignment = System.Windows.VerticalAlignment.Top; grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; CheckBox checkBoxIOStatus = new CheckBox(); checkBoxIOStatus.VerticalAlignment = System.Windows.VerticalAlignment.Top; checkBoxIOStatus.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBoxIOStatus.Margin = new Thickness(0, 2, 0, 2); Binding bd = new Binding("Value"); bd.Source = ioInfo; if (ioInfo.GetType().GetProperty("Value").GetSetMethod(false) != null) bd.Mode = BindingMode.TwoWay; else bd.Mode = BindingMode.OneWay; checkBoxIOStatus.SetBinding(CheckBox.IsCheckedProperty, bd); bd = new Binding("Name"); bd.Source = ioInfo; bd.Mode = BindingMode.OneTime; checkBoxIOStatus.SetBinding(CheckBox.ContentProperty, bd); bd = new Binding("Description"); bd.Source = ioInfo; bd.Mode = BindingMode.OneTime; checkBoxIOStatus.SetBinding(CheckBox.ToolTipProperty, bd); grid.Children.Add(checkBoxIOStatus); Grid.SetRow(checkBoxIOStatus, rowCount); Grid.SetColumn(checkBoxIOStatus, 0); rowCount++; } return grid; }
private void CreateDuplexCaptureOperationInfo(Grid grid, FALibrary.Part.FAPart part, string name, Action<object> OnAction, Action<object> OffAction, Action<object> StopAction, Func<bool> IsOn, Func<bool> IsOff, string onName, string offName) { GeneralOperationInfo obj = new GeneralOperationInfo(); RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(100, GridUnitType.Auto); rd.MinHeight = 100; SetOperationGridColor(grid, grid.RowDefinitions.Count - 1); grid.RowDefinitions.Add(rd); obj.Name = name; obj.On = OnAction; obj.Off = OffAction; obj.StatusOnName = onName; obj.StatusOffName = offName; obj.IsOn = IsOn; obj.IsOff = IsOff; Label labelName = new Label(); labelName.Height = Double.NaN; labelName.Width = Double.NaN; labelName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; labelName.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; labelName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelName.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelName.Margin = new Thickness(2); Binding bd = new Binding("Name"); bd.Source = obj; bd.Mode = BindingMode.OneWay; labelName.SetBinding(Label.ContentProperty, bd); Label labelStatus = new Label(); labelStatus.Height = Double.NaN; labelStatus.Width = Double.NaN; labelStatus.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; labelStatus.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; labelStatus.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelStatus.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelStatus.Margin = new Thickness(2); bd = new Binding("Status"); bd.Source = obj; bd.Mode = BindingMode.OneWay; labelStatus.SetBinding(Label.ContentProperty, bd); Grid gridInputIOList = CreatePartInputIOList(part); Grid gridOutputIOList = CreatePartOutputIOList(part); Button buttonOn = new Button(); buttonOn.Height = Double.NaN; buttonOn.Width = Double.NaN; buttonOn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; buttonOn.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; buttonOn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; buttonOn.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; buttonOn.Content = onName; buttonOn.Margin = new Thickness(2); buttonOn.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { OnAction(sender); }; buttonOn.PreviewMouseUp += delegate(object sender, MouseButtonEventArgs e) { StopAction(sender); }; Button buttonOff = new Button(); buttonOff.Height = Double.NaN; buttonOff.Width = Double.NaN; buttonOff.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; buttonOff.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; buttonOff.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; buttonOff.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; buttonOff.Content = offName; buttonOff.Margin = new Thickness(2); buttonOff.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { OffAction(sender); }; buttonOff.PreviewMouseUp += delegate(object sender, MouseButtonEventArgs e) { StopAction(sender); }; ColumnDefinition col1 = new ColumnDefinition(); col1.Width = new GridLength(100, GridUnitType.Star); ColumnDefinition col2 = new ColumnDefinition(); col2.Width = new GridLength(100, GridUnitType.Star); Grid buttonGrid = new Grid(); buttonGrid.Width = double.NaN; buttonGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; buttonGrid.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; buttonGrid.Height = double.NaN; buttonGrid.Margin = new Thickness(0); buttonGrid.ColumnDefinitions.Add(col1); buttonGrid.ColumnDefinitions.Add(col2); buttonGrid.Children.Add(buttonOn); buttonGrid.Children.Add(buttonOff); Grid.SetColumn(buttonOn, 0); Grid.SetColumn(buttonOff, 1); TextBox textBoxRepeat = new TextBox(); textBoxRepeat.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; textBoxRepeat.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; textBoxRepeat.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; textBoxRepeat.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; textBoxRepeat.Height = Double.NaN; textBoxRepeat.Width = Double.NaN; textBoxRepeat.Margin = new Thickness(2); bd = new Binding("RepeatTime"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; textBoxRepeat.SetBinding(TextBox.TextProperty, bd); CheckBox checkBoxRepeatUse = new CheckBox(); checkBoxRepeatUse.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBoxRepeatUse.VerticalAlignment = System.Windows.VerticalAlignment.Center; bd = new Binding("RepeatUse"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; checkBoxRepeatUse.SetBinding(CheckBox.IsCheckedProperty, bd); int rowCount = grid.RowDefinitions.Count - 1; grid.Children.Add(labelName); Grid.SetColumn(labelName, 0); Grid.SetRow(labelName, rowCount); grid.Children.Add(labelStatus); Grid.SetColumn(labelStatus, 1); Grid.SetRow(labelStatus, rowCount); grid.Children.Add(buttonGrid); Grid.SetColumn(buttonGrid, 2); Grid.SetRow(buttonGrid, rowCount); grid.Children.Add(gridInputIOList); Grid.SetColumn(gridInputIOList, 3); Grid.SetRow(gridInputIOList, rowCount); grid.Children.Add(gridOutputIOList); Grid.SetColumn(gridOutputIOList, 4); Grid.SetRow(gridOutputIOList, rowCount); grid.Children.Add(textBoxRepeat); Grid.SetColumn(textBoxRepeat, 5); Grid.SetRow(textBoxRepeat, rowCount); grid.Children.Add(checkBoxRepeatUse); Grid.SetColumn(checkBoxRepeatUse, 6); Grid.SetRow(checkBoxRepeatUse, rowCount); _ioOperationList.Add(obj); bd = new Binding("IsEnabledOutputIODirectControl"); bd.Source = this; bd.Mode = BindingMode.OneWay; gridOutputIOList.SetBinding(ListView.IsEnabledProperty, bd); }
private void CreateOnOffStopIndependentOperationInfo(Grid grid, FALibrary.Part.FAPart part, string name, Action<object> OnAction, Action<object> OffAction, Action<object> StopAction, Func<bool> IsOn, Func<bool> IsOff, string onName, string offName) { GeneralOperationInfo obj = new GeneralOperationInfo(); RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(100, GridUnitType.Auto); rd.MinHeight = 100; grid.RowDefinitions.Add(rd); SetOperationGridColor(grid, grid.RowDefinitions.Count - 1); obj.Name = name; obj.On = OnAction; obj.Off = OffAction; obj.StatusOnName = onName; obj.StatusOffName = offName; obj.IsOn = IsOn; obj.IsOff = IsOff; Label labelName = new Label(); labelName.Height = Double.NaN; labelName.Width = Double.NaN; labelName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; labelName.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; labelName.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelName.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelName.Margin = new Thickness(2); Binding bd = new Binding("Name"); bd.Source = obj; bd.Mode = BindingMode.OneWay; labelName.SetBinding(Label.ContentProperty, bd); Label labelStatus = new Label(); labelStatus.Height = Double.NaN; labelStatus.Width = Double.NaN; labelStatus.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch; labelStatus.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch; labelStatus.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; labelStatus.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; labelStatus.Margin = new Thickness(2); bd = new Binding("Status"); bd.Source = obj; bd.Mode = BindingMode.OneWay; labelStatus.SetBinding(Label.ContentProperty, bd); Grid gridInputIOList = CreatePartInputIOList(part); Grid gridOutputIOList = CreatePartOutputIOList(part); Button buttonOn, buttonOff, buttonStop; Grid gridButton = CreateOnOffStopButtonGrid(out buttonOn, out buttonOff, out buttonStop); buttonOn.Content = onName; buttonOff.Content = offName; buttonStop.Content = "STOP"; buttonOn.Click += delegate(object sender, RoutedEventArgs e) { OnAction(sender); }; buttonOff.Click += delegate(object sender, RoutedEventArgs e) { OffAction(sender); }; buttonStop.Click += delegate(object sender, RoutedEventArgs e) { StopAction(sender); }; TextBox textBoxRepeat = new TextBox(); textBoxRepeat.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; textBoxRepeat.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; textBoxRepeat.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; textBoxRepeat.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; textBoxRepeat.Height = Double.NaN; textBoxRepeat.Width = Double.NaN; textBoxRepeat.Margin = new Thickness(2); bd = new Binding("RepeatTime"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; textBoxRepeat.SetBinding(TextBox.TextProperty, bd); CheckBox checkBoxRepeatUse = new CheckBox(); checkBoxRepeatUse.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBoxRepeatUse.VerticalAlignment = System.Windows.VerticalAlignment.Center; checkBoxRepeatUse.LayoutTransform = new ScaleTransform(CHECKBOX_SIZE, CHECKBOX_SIZE); bd = new Binding("RepeatUse"); bd.Source = obj; bd.Mode = BindingMode.TwoWay; checkBoxRepeatUse.SetBinding(CheckBox.IsCheckedProperty, bd); int rowCount = grid.RowDefinitions.Count - 1; grid.Children.Add(labelName); Grid.SetColumn(labelName, 0); Grid.SetRow(labelName, rowCount); grid.Children.Add(labelStatus); Grid.SetColumn(labelStatus, 1); Grid.SetRow(labelStatus, rowCount); grid.Children.Add(gridInputIOList); Grid.SetColumn(gridInputIOList, 2); Grid.SetRow(gridInputIOList, rowCount); grid.Children.Add(gridOutputIOList); Grid.SetColumn(gridOutputIOList, 3); Grid.SetRow(gridOutputIOList, rowCount); grid.Children.Add(gridButton); Grid.SetColumn(gridButton, 4); Grid.SetRow(gridButton, rowCount); grid.Children.Add(textBoxRepeat); Grid.SetColumn(textBoxRepeat, 5); Grid.SetRow(textBoxRepeat, rowCount); grid.Children.Add(checkBoxRepeatUse); Grid.SetColumn(checkBoxRepeatUse, 6); Grid.SetRow(checkBoxRepeatUse, rowCount); _ioOperationList.Add(obj); bd = new Binding("IsEnabledOutputIODirectControl"); bd.Source = this; bd.Mode = BindingMode.OneWay; gridOutputIOList.SetBinding(ListView.IsEnabledProperty, bd); }
private CheckBox CreateCheckBox(PropertyInfo propertyInfo) { CheckBox checkBox = new CheckBox(); checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBox.VerticalAlignment = System.Windows.VerticalAlignment.Center; Binding bd = new Binding(propertyInfo.Name); bd.Source = _device; bd.Mode = BindingMode.TwoWay; checkBox.SetBinding(CheckBox.IsCheckedProperty, bd); return checkBox; }
/// <summary> /// Creates a check box control. /// </summary> /// <param name="d"> /// The definition. /// </param> /// <param name="index"> /// The index. /// </param> /// <returns> /// A CheckBox. /// </returns> protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition d, int index) { if (d.IsReadOnly) { var cm = new CheckMark { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = d.HorizontalAlignment }; cm.SetBinding(CheckMark.IsCheckedProperty, d.CreateBinding(index)); return cm; } var c = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = d.HorizontalAlignment, IsEnabled = !d.IsReadOnly }; c.SetBinding(ToggleButton.IsCheckedProperty, d.CreateBinding(index)); return c; }
/// <summary> /// Creates the check box control. /// </summary> /// <param name="property">The property.</param> /// <returns></returns> protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition property) { var c = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = property.HorizontalAlignment }; c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding()); return c; }
Ctrl.Control ConvertElement(VM.Element vm) { var t = vm.GetType(); if (t == typeof(VM.TableView)) { var tv = (VM.TableView)vm; var lv = new Ctrl.ListView { DataContext = tv }; lv.SetBinding(Ctrl.ListView.ItemsSourceProperty, tv.Path); lv.SetBinding(Ctrl.ListView.VisibilityProperty, new Binding("Items.Count") { RelativeSource = RelativeSource.Self, Mode = BindingMode.OneWay, Converter = new IntToVisibilityConverter() }); if (tv.ItemType.IsPrimitive != true) { var gv = new Ctrl.GridView(); var props = tv.ItemType.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var xt in props) { gv.Columns.Add(new Ctrl.GridViewColumn { DisplayMemberBinding = new Binding(xt.Name), Header = xt.Name, Width = Double.NaN, }); } lv.View = gv; } return(lv); } if (t == typeof(VM.SlideInput)) { var slider = new Ctrl.Slider { Name = vm.Name, DataContext = (VM.SlideInput)vm, }; slider.SetBinding(Ctrl.Slider.ValueProperty, vm.Path); return(slider); } if (t == typeof(VM.EnumInput)) { return(new MechaCtrl.EnumInput { Name = vm.Name, ViewModel = (VM.EnumInput)vm }); } if (t == typeof(VM.TextView)) { return(new MechaCtrl.TextView { Name = vm.Name, ViewModel = (VM.TextView)vm, }); } if (t == typeof(VM.CheckBox)) { var chkBox = new Ctrl.CheckBox { Name = vm.Name, DataContext = (VM.CheckBox)vm, }; chkBox.SetBinding(Ctrl.CheckBox.IsCheckedProperty, vm.Path); return(chkBox); } if (t == typeof(VM.DateInput)) { return(new MechaCtrl.DateInput { Name = vm.Name, ViewModel = (VM.DateInput)vm, }); } if (t == typeof(VM.TextInput)) { return(new MechaCtrl.TextInput { Name = vm.Name, ViewModel = (VM.TextInput)vm, }); } if (t == typeof(VM.PathInput)) { return(new MechaCtrl.PathInput { Name = vm.Name, ViewModel = (VM.PathInput)vm, }); } if (t == typeof(VM.PasswordInput)) { return(new MechaCtrl.PasswordInput { Name = vm.Name, ViewModel = (VM.PasswordInput)vm, }); } if (t == typeof(VM.Button)) { var btn = new Ctrl.Button { Name = vm.Name, DataContext = vm, }; var btnVm = (VM.Button)vm; btn.Click += async(o, e) => await TryInvokeButton(btnVm); return(btn); } throw new NotImplementedException(); }
private void UpdateStackPanel() { mainStackPanel.Children.Clear(); int longestDescr = 0; bool empty = true; foreach (ILegendable l in graphsInLegend) { if (!l.ShowInLegend) continue; empty = false; StackPanel legendItem = new StackPanel(); ToolTip tooltip = new ToolTip() { Content = l.Description}; legendItem.Orientation = Orientation.Horizontal; Line line = new Line(); line.SetBinding(Line.StrokeProperty, new Binding(){Source =l, Path = new PropertyPath("LineColor")}); line.StrokeThickness = l.LineThickness; line.X2 = 0; line.Y2 = 0; line.X1 = 15; line.Y1 = 15; ToolTipService.SetToolTip(legendItem, tooltip); legendItem.Children.Add(line); TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(5.0); if (l.Description.Length > longestDescr) longestDescr = l.Description.Length; if (l.Description.Length > AllowedDescriptionLength+1) textBlock.Text = String.Format("{0}...", l.Description.Remove(AllowedDescriptionLength)); else textBlock.Text = l.Description; Binding bd2 = new Binding(); bd2.Source = l; bd2.Path = new PropertyPath("Description"); bd2.Mode = BindingMode.OneWay; textBlock.SetBinding(TextBlock.TextProperty, bd2); legendItem.Children.Add(textBlock); //If possible include a checkbox to switch the graph on and off legendItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; CheckBox c = new CheckBox(); c.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; c.VerticalAlignment = System.Windows.VerticalAlignment.Center; Binding bd = new Binding(); bd.Source = l; bd.Path = new PropertyPath("ShowInPlotter"); bd.Mode = BindingMode.TwoWay; c.SetBinding(CheckBox.IsCheckedProperty, bd); legendItem.Children.Add(c); mainStackPanel.Children.Add(legendItem); } if (empty) { if (Height != 0 && Width != 0) { previousSize = new Size(Width, Height); Width = 0; Height = 0; } } else { Width = previousSize.Width; Height = previousSize.Height; } //if(EnableAutomaticDescriptionLength) //{ // bool changed = false; // double centralGridWidth = Plotter.CentralGrid.ActualWidth; // if (centralGridWidth / 3 < ActualWidth) // { // changed = true; // if (AllowedDescriptionLength > longestDescr) // AllowedDescriptionLength = longestDescr - 3; // else AllowedDescriptionLength--; // } // else if((longestDescr>AllowedDescriptionLength+3) // && (AllowedDescriptionLength<int.MaxValue-3) // && centralGridWidth / 2.8 > ActualWidth) // { // AllowedDescriptionLength++; // changed = true; // } // if (changed) // legendable_VisualizationChanged(this, EventArgs.Empty); //} }