Exemplo n.º 1
1
        private void UpdateContent()
        {
            if (panel == null)
                return;

            panel.Children.Clear();
            
            if (Value == null)
                return;
            
            var enumValues = Enum.GetValues(Value.GetType()).FilterOnBrowsableAttribute();
            var converter = new EnumToBooleanConverter { EnumType = Value.GetType() };
            var relativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(RadioButtonList), 1);
            var descriptionConverter = new EnumDescriptionConverter();

            foreach (var itemValue in enumValues )
            {
                var rb = new RadioButton { Content = descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture) };
                // rb.IsChecked = Value.Equals(itemValue);

                var isCheckedBinding = new Binding("Value")
                                           {
                                               Converter = converter,
                                               ConverterParameter = itemValue,
                                               Mode = BindingMode.TwoWay,
                                               RelativeSource = relativeSource
                                           };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                var itemMarginBinding = new Binding("ItemMargin") { RelativeSource = relativeSource };
                rb.SetBinding(MarginProperty, itemMarginBinding);

                panel.Children.Add(rb);
            }
        }
Exemplo n.º 2
0
        private void PopulateAccentsStackPanel()
        {
            foreach (var accent in ThemeManager.Accents)
            {
                var rb = new RadioButton
                {
                    Margin           = new Thickness(2),
                    Content          = accent.Name,
                    GroupName        = "accents",
                    FocusVisualStyle = null,
                    Foreground       = (Brush)accent.Resources["AccentBaseColorBrush"]
                };
                rb.Checked += AccentRb_Checked;

                var binding = new Binding
                {
                    Path               = new PropertyPath("Config.Accent"),
                    Converter          = new StringToBooleanConverter(),
                    ConverterParameter = (string)rb.Content
                };
                rb.SetBinding(ToggleButton.IsCheckedProperty, binding);

                SpAccents.Children.Add(rb);
            }
        }
Exemplo n.º 3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            True = (RadioButton)GetTemplateChild("PART_True");
            True.SetBinding(RadioButton.IsCheckedProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.TwoWay });
            True.Checked += Checked;
            False = (RadioButton)GetTemplateChild("PART_False");
            False.SetBinding(RadioButton.IsCheckedProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.TwoWay, Converter = new BooleanReverseValueConverter() });
            False.Checked += Checked;
        }
Exemplo n.º 4
0
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            var radioButton = new RadioButton { Margin = new Thickness(3.0, 0.0, 3.0, 0.0) };

            if (DataMemberBinding != null)
                radioButton.SetBinding(ToggleButton.IsCheckedProperty, DataMemberBinding);

            radioButton.Checked += RadioButtonChecked;

            return radioButton;
        }
Exemplo n.º 5
0
        public override void SetupCustomUIElements(object ui)
        {
            var nodeUI = ui as dynNodeView;

            //add a text box to the input grid of the control
            var rbTrue  = new System.Windows.Controls.RadioButton();
            var rbFalse = new System.Windows.Controls.RadioButton();

            rbTrue.VerticalAlignment  = System.Windows.VerticalAlignment.Center;
            rbFalse.VerticalAlignment = System.Windows.VerticalAlignment.Center;

            //use a unique name for the button group
            //so other instances of this element don't get confused
            string groupName = Guid.NewGuid().ToString();

            rbTrue.GroupName  = groupName;
            rbFalse.GroupName = groupName;

            rbTrue.Content  = "1";
            rbTrue.Padding  = new Thickness(5, 0, 12, 0);
            rbFalse.Content = "0";
            rbFalse.Padding = new Thickness(5, 0, 0, 0);

            var wp = new WrapPanel {
                HorizontalAlignment = HorizontalAlignment.Center
            };

            wp.Children.Add(rbTrue);
            wp.Children.Add(rbFalse);
            nodeUI.inputGrid.Children.Add(wp);

            //rbFalse.IsChecked = true;
            rbTrue.Checked  += new System.Windows.RoutedEventHandler(rbTrue_Checked);
            rbFalse.Checked += new System.Windows.RoutedEventHandler(rbFalse_Checked);

            rbFalse.DataContext = this;
            rbTrue.DataContext  = this;

            var rbTrueBinding = new System.Windows.Data.Binding("Value")
            {
                Mode = BindingMode.TwoWay,
            };

            rbTrue.SetBinding(System.Windows.Controls.RadioButton.IsCheckedProperty, rbTrueBinding);

            var rbFalseBinding = new System.Windows.Data.Binding("Value")
            {
                Mode      = BindingMode.TwoWay,
                Converter = new InverseBoolDisplay()
            };

            rbFalse.SetBinding(System.Windows.Controls.RadioButton.IsCheckedProperty, rbFalseBinding);
        }
Exemplo n.º 6
0
        public override void SetupCustomUIElements(dynNodeView nodeUI)
        {
            this.dynamoViewModel = nodeUI.ViewModel.DynamoViewModel;

            //add a text box to the input grid of the control
            var rbTrue = new RadioButton();
            var rbFalse = new RadioButton();
            rbTrue.VerticalAlignment = VerticalAlignment.Center;
            rbFalse.VerticalAlignment = VerticalAlignment.Center;

            //use a unique name for the button group
            //so other instances of this element don't get confused
            string groupName = Guid.NewGuid().ToString();
            rbTrue.GroupName = groupName;
            rbFalse.GroupName = groupName;

            rbTrue.Content = "True";
            rbTrue.Padding = new Thickness(0,0,12,0);
            rbFalse.Content = "False";
            rbFalse.Padding = new Thickness(0);
            var wp = new WrapPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Margin = new Thickness(10,5,10,0),
                Orientation = Orientation.Horizontal
            };

            wp.Children.Add(rbTrue);
            wp.Children.Add(rbFalse);
            nodeUI.inputGrid.Children.Add(wp);

            //rbFalse.IsChecked = true;
            rbTrue.Checked += OnRadioButtonClicked;
            rbFalse.Checked += OnRadioButtonClicked;

            rbFalse.DataContext = this;
            rbTrue.DataContext = this;

            var rbTrueBinding = new Binding("Value") { Mode = BindingMode.TwoWay, };
            rbTrue.SetBinding(ToggleButton.IsCheckedProperty, rbTrueBinding);

            var rbFalseBinding = new Binding("Value")
            {
                Mode = BindingMode.TwoWay,
                Converter = new InverseBoolDisplay()
            };
            rbFalse.SetBinding(ToggleButton.IsCheckedProperty, rbFalseBinding);
        }
Exemplo n.º 7
0
        public BoolEditor(WorkFrame frame)
            : base(frame)
        {
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;

            RadioButton yes = new RadioButton();
            yes.DataContext = this;
            yes.GroupName = "Bool";
            yes.Content = "是";
            panel.Children.Add(yes);

            RadioButton no = new RadioButton();
            no.GroupName = "Bool";
            no.Content = "否";
            panel.Children.Add(no);

            var binding = new Binding("Value");
            binding.Mode = BindingMode.TwoWay;
            yes.SetBinding(RadioButton.IsCheckedProperty, binding);

            Content = panel;
        }
Exemplo n.º 8
0
        public SexEditor(WorkFrame frame)
            : base(frame)
        {
            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;

            RadioButton girl = new RadioButton();
            girl.GroupName = "Sex";
            girl.Content = "女";
            panel.Children.Add(girl);

            RadioButton boy = new RadioButton();
            boy.DataContext = this;
            boy.GroupName = "Sex";
            boy.Content = "男";
            panel.Children.Add(boy);

            var binding = new Binding("Value");
            binding.Mode = BindingMode.TwoWay;
            boy.SetBinding(RadioButton.IsCheckedProperty, binding);

            Content = panel;
        }
Exemplo n.º 9
0
        private void PopulateThemesStackPanel()
        {
            foreach (var appTheme in ThemeManager.AppThemes)
            {
                var rb = new RadioButton
                {
                    Margin           = new Thickness(2),
                    Content          = appTheme.Name,
                    GroupName        = "themes",
                    FocusVisualStyle = null
                };
                rb.Checked += ThemeRb_Checked;

                var binding = new Binding
                {
                    Path               = new PropertyPath("Config.Theme"),
                    Converter          = new StringToBooleanConverter(),
                    ConverterParameter = (string)rb.Content
                };
                rb.SetBinding(ToggleButton.IsCheckedProperty, binding);

                SpThemes.Children.Add(rb);
            }
        }
Exemplo n.º 10
0
        private static ModelPropertyUiInfo CreateEnumField(Grid parent,
            Type enumType,
            DisplayPropertyInfo property,
            String bindingPath,
            Style style,
            int row,
            int column)
        {
            ModelPropertyUiInfo elememtsInfo = new ModelPropertyUiInfo(property);

            // create label
            Label labelElement = CreateLabel(property, row, column);
            parent.Children.Add(labelElement);
            elememtsInfo.Label = labelElement;

            // create inputs
            var panel = new WrapPanel()
            {
                Orientation = Orientation.Horizontal,
                Margin = new Thickness(4),
            };
            Grid.SetRow(panel, row);
            Grid.SetColumn(panel, checked(column + 1));
            parent.Children.Add(panel);
            elememtsInfo.Content = panel;

            if (!enumType.IsEnum) return elememtsInfo;
            Array enumValues = Enum.GetValues(enumType);
            foreach (var item in enumValues)
            {
                RadioButton control = new RadioButton
                {
                    Name = "radioButton" + property.PropertyName + "_" + item.ToString(),
                    // TODO: Localization for enum values
                    Content = item.ToString(),
                    GroupName = property.PropertyName,
                    Margin = new Thickness(4),
                };
                if (style != null)
                {
                    control.Style = style;
                }
                control.SetBinding(ToggleButton.IsCheckedProperty,
                    ModelUiCreatorHelper.CreateBinding(property, bindingPath, new EnumToBooleanConverter(), item.ToString()));

                if (property.IsReadOnly)
                {
                    control.IsEnabled = false;
                }

                panel.Children.Add(control);
            }

            return elememtsInfo;
        }
Exemplo n.º 11
0
        void CreatePluginViews()
        {
            var views =
                PluginsManager.Current.Plugins
                    .Where(p => p.StreamViews != null)
                    .SelectMany(p => p.StreamViews)
                    .ToList();

            foreach (var view in views)
            {
                // Create radio button to switch to this view
                var button = new RadioButton
                {
                    GroupName = "StreamViewToggle",
                    Content = view.Header,
                    Style = (Style)FindResource("SwitcherToggleIconRadio")
                };

                IStreamViewPlugin view1 = view;
                button.Click += delegate
                {
                    SettingsManager.ClientSettings.AppConfiguration.DefaultView = view1.Header;
                    SettingsManager.Save();

                    view1.SwitchToView();
                };
                button.DataContext = view;
                button.SetBinding(IsEnabledProperty, "CanSwitchToView");

                StreamViewsRadioButtons.Children.Add(button);
            }
        }
Exemplo n.º 12
0
        /// <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;
        }
Exemplo n.º 13
0
        private void SetupControl(FoundOps.Core.Models.CoreEntities.Repeat schedule)
        {
            var monthlyFrequencyDetailsStackPanel = new StackPanel();

            if (schedule == null || schedule.AvailableMonthlyFrequencyDetailTypes == null)
            {
                this.Content = null;
                this.InvalidateArrange();
                return;
            }

            foreach (var monthlyFrequencyDetail in schedule.AvailableMonthlyFrequencyDetailTypes)
            {
                var monthlyFrequencyDetailRadioButton = new RadioButton { GroupName = "RepeatOn" };

                monthlyFrequencyDetailRadioButton.SetBinding(ContentControl.ContentProperty,
                                                             new Binding("StartDate")
                                                                 {
                                                                     Source = schedule,
                                                                     Converter =
                                                                         new MonthlyFrequencyDetailToStringConverter(
                                                                         monthlyFrequencyDetail)
                                                                 });

                monthlyFrequencyDetailRadioButton.SetBinding(ToggleButton.IsCheckedProperty,
                                                             new Binding("FrequencyDetailAsMonthlyFrequencyDetail")
                                                                 {
                                                                     Source = schedule,
                                                                     Converter =
                                                                         new MonthlyFrequencyDetailIsCheckedConverter(
                                                                         monthlyFrequencyDetail)
                                                                 });

                var detail = monthlyFrequencyDetail;
                monthlyFrequencyDetailRadioButton.Checked += (o, args) =>
                                                                 {
                                                                     Value.FrequencyDetailAsMonthlyFrequencyDetail = detail;
                                                                 };

                monthlyFrequencyDetailsStackPanel.Children.Add(monthlyFrequencyDetailRadioButton);
            }

            this.Content = monthlyFrequencyDetailsStackPanel;
            this.InvalidateArrange();
        }
Exemplo n.º 14
0
        protected override System.Windows.FrameworkElement BuildGUIConfiguration()
        {
            RadioButton r1 = new RadioButton()
            {
                Content = "Row",
                GroupName = "DeleteMode",
            };
            r1.SetBinding(RadioButton.IsCheckedProperty, new Binding("DeleteRow"));

            RadioButton r2 = new RadioButton()
            {
                Content = "Column",
                GroupName = "DeleteMode",
            };
            r2.SetBinding(RadioButton.IsCheckedProperty, new Binding("DeleteColumn"));

            StackPanel panel = new StackPanel();
            panel.Children.Add(r1);
            panel.Children.Add(r2);

            return panel;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Updates the content.
        /// </summary>
        private void UpdateContent()
        {
            if (this.panel == null)
            {
                return;
            }

            this.panel.Children.Clear();

            var enumType = this.EnumType;
            if (enumType != null)
            {
                var ult = Nullable.GetUnderlyingType(enumType);
                if (ult != null)
                {
                    enumType = ult;
                }
            }

            if (this.Value != null)
            {
                enumType = this.Value.GetType();
            }

            if (enumType == null || !typeof(Enum).IsAssignableFrom(enumType))
            {
                return;
            }

            var enumValues = Enum.GetValues(enumType).FilterOnBrowsableAttribute();
            var converter = new EnumToBooleanConverter { EnumType = enumType };

            foreach (var itemValue in enumValues)
            {
                var rb = new RadioButton
                    {
                        Content =
                            this.DescriptionConverter.Convert(
                                itemValue, typeof(string), null, CultureInfo.CurrentCulture),
                        Padding = this.ItemPadding
                    };

                var isCheckedBinding = new Binding("Value")
                    {
                       Converter = converter, ConverterParameter = itemValue, Source = this, Mode = BindingMode.TwoWay
                    };
                rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding);

                rb.SetBinding(MarginProperty, new Binding("ItemMargin") { Source = this });

                this.panel.Children.Add(rb);
            }
        }
Exemplo n.º 16
0
        private UIElement GetLogControl(List<WorkReportLogEntity> logs, int rowIndex, int columnCount, int logCount,
            GridLength length)
        {
            int margin = 2;
            string groupName = Guid.NewGuid().ToString();
            var userLogControl = new LogGrid
            {
                Header = "LOG质量"
            };

            var gridLog = new Grid
            {
                ShowGridLines = false,

                Background = GetColor(5)
            };

            var logGroup = logs;
            if (logGroup.Count > 0)
            {
                for (int i1 = 0; i1 < columnCount + margin; i1++)
                {
                    if (i1==0)
                    {
                       gridLog.ColumnDefinitions.Add(new ColumnDefinition
                       {
                        Width =new GridLength(115),
                       });
                    }
                    else
                    {
                         gridLog.ColumnDefinitions.Add(new ColumnDefinition
                    {
                        Width =new GridLength(100),
                    });
                    }

                    Rectangle rec = CreateVertLine(i1, logGroup.Count + 1);

                    gridLog.Children.Add(rec);
                }

                for (int i1 = 0; i1 < logGroup.Count + 1; i1++)
                {
                    gridLog.RowDefinitions.Add(new RowDefinition
                    {
                        Height = GridLength.Auto,
                        MinHeight = 40
                    });
                    Rectangle rectSub = CreateHorLine(i1, columnCount + margin);
                    if (i1 == logGroup.Count() && rowIndex != logCount  * 2)
                    {
                        rectSub.Height = 2;
                        rectSub.Fill = new SolidColorBrush(Colors.Black);
                        rectSub.Margin = new Thickness(0, 1, 0, -1);
                    }
                    gridLog.Children.Add(rectSub);
                }

                Rectangle rectlogo = CreateRectangler(2);
                rectlogo.Margin = new Thickness(1);
                Grid.SetColumn(rectlogo, 0);
                Grid.SetColumnSpan(rectlogo,2);
                Grid.SetRow(rectlogo, 0);
                gridLog.Children.Add(rectlogo);

                var lableLogName = new Border
                {
                    Child = new TextBlock
                    {
                        Text = "LOG名称",
                        FontSize = 12,
                        FontWeight = FontWeights.Bold,
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin = new Thickness(20, 0, 0, 0)
                    },
                    Margin = new Thickness(1, 0, 1, 1)
                };
                lableLogName.SetValue(Canvas.ZIndexProperty, 10);
                Grid.SetColumn(lableLogName, 0);

                Grid.SetRow(lableLogName, 0);
                lableLogName.HorizontalAlignment = HorizontalAlignment.Stretch;
                lableLogName.VerticalAlignment = VerticalAlignment.Stretch;
                gridLog.Children.Add(lableLogName);

                var lableLogQuality = new Border
                {
                    Child = new TextBlock
                    {
                        Text = "Log质量",
                        FontSize = 12,
                        FontWeight = FontWeights.Bold,
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin = new Thickness(20, 0, 0, 0)
                    },
                    Margin = new Thickness(1, 0, 1, 1)
                };
                lableLogName.SetValue(Canvas.ZIndexProperty, 10);
                Grid.SetColumn(lableLogQuality, 1);

                Grid.SetRow(lableLogQuality, 0);
                lableLogName.HorizontalAlignment = HorizontalAlignment.Stretch;
                lableLogName.VerticalAlignment = VerticalAlignment.Stretch;
                gridLog.Children.Add(lableLogQuality);

                for (int m = 0; m < columnCount; m++)
                {
                    var kpi = logs[0].Kpis[m];
                    var lableLog = new TextBlock
                    {
                        Text = kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)"),
                        FontSize = 12,
                        FontWeight = FontWeights.Bold,
                        MaxWidth = 80,
                        TextWrapping = TextWrapping.Wrap
                    };
                    lableLog.SetValue(ToolTipService.ToolTipProperty,
                        kpi.KpiName + (kpi.KpiName.Contains("FTP") ? "" : "(%)"));
                    Grid.SetColumn(lableLog, m + margin);
                    lableLog.VerticalAlignment = VerticalAlignment.Center;
                    lableLog.HorizontalAlignment = HorizontalAlignment.Center;
                    Grid.SetRow(lableLog, 0);
                    lableLog.SetValue(Canvas.ZIndexProperty, 10);
                    gridLog.Children.Add(lableLog);
                }

                var countLog = 0;
                for (int i = 0; i < logGroup.Count(); i++)
                {
                    countLog++;
                    StackPanel stackPanelLog = new StackPanel() {Orientation = Orientation.Horizontal};

                    var rb = new RadioButton() { Tag = logGroup[i], VerticalAlignment = VerticalAlignment.Center, GroupName = groupName+logGroup[i].LogServertype };
                    rb.SetBinding(RadioButton.IsCheckedProperty,
                        new Binding() { Source = rb.Tag, Path = new PropertyPath("IsSelected"), Mode = BindingMode.TwoWay });

                    stackPanelLog.Children.Add(rb);
                    var logtxt = new TextBlock
                    {
                        FontSize = 12,
                        FontWeight = FontWeights.Bold,
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Margin = new Thickness(20, 0, 0, 0)
                    };
                    var run = new Run
                    {
                        Text = logGroup[i].LogName,
                    };
                    logtxt.Inlines.Add(run);
                    var br = new LineBreak();
                    logtxt.Inlines.Add(br);

                    var dataType = new Underline();

                    dataType.Inlines.Add(new Run
                    {
                        Text = logGroup[i].LogServertype + "(打点图)"
                    });
                    logtxt.Inlines.Add(dataType);
                    stackPanelLog.Children.Add(logtxt);
                    var lableNameLog1 = new Border
                    {
                        Child = stackPanelLog,
                        Margin = new Thickness(1, 0, 1, 1),
                        Cursor = Cursors.Hand
                    };

                    lableNameLog1.MouseLeftButtonDown +=
                        (s, e) =>
                        {
                        };
                    lableNameLog1.SetValue(Canvas.ZIndexProperty, 10);
                    Grid.SetColumn(lableNameLog1, 0);

                    Grid.SetRow(lableNameLog1, countLog);
                    lableNameLog1.VerticalAlignment = VerticalAlignment.Stretch;
                    lableNameLog1.HorizontalAlignment = HorizontalAlignment.Stretch;
                    gridLog.Children.Add(lableNameLog1);

                    Rectangle rectbg = CreateGridRowBackground(1, countLog);
                    gridLog.Children.Add(rectbg);

                    TextBlock logQuality = new TextBlock()
                    {
                        Foreground = GetColor(logGroup[i].Result),
                        FontFamily = new FontFamily("Microsoft YaHei"),
                        FontSize = 14,
                        FontWeight = FontWeights.Bold,

                    };

                    logQuality.Text = GetResult(logGroup[i].Result);
                    Grid.SetColumn(logQuality, 1);
                    Grid.SetRow(logQuality, countLog);
                    logQuality.VerticalAlignment = VerticalAlignment.Center;
                    logQuality.HorizontalAlignment = HorizontalAlignment.Center;
                    gridLog.Children.Add(logQuality);

                    if (logs[i].Kpis==null)
                    {
                        continue;
                    }
                    for (int m = 0; m < columnCount; m++)
                    {

                        var kpi = logs[i].Kpis[m];

                        Rectangle newrect = CreateRectangler(1);
                        newrect.Margin = new Thickness(1, 1, 1, 1);
                        Grid.SetColumn(newrect, m + margin);
                        Grid.SetRow(newrect, 0);
                        gridLog.Children.Add(newrect);

                        var borderlog = new TextBlock
                        {
                            Text =
                                kpi.KpiName.Contains("FTP")
                                    ? kpi.KpiValue.ToString()
                                    : (kpi.KpiValue.Value * 100).ToString("00.0"),
                            Foreground =GetColor(logs[i].Result),
                            FontFamily = new FontFamily("Microsoft YaHei"),
                            FontSize = 12,
                            VerticalAlignment = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Center
                        };

                        borderlog.SetValue(ToolTipService.ToolTipProperty,
                            kpi.KpiRange);
                        borderlog.SetValue(Canvas.ZIndexProperty, 100);
                        Grid.SetColumn(borderlog, m + margin);
                        Grid.SetRow(borderlog, countLog);
                        gridLog.Children.Add(borderlog);
                    }
                }
            }
            userLogControl.Content = new Border() { Child = gridLog,BorderBrush = new SolidColorBrush(Colors.Black),BorderThickness = new Thickness(1)}; ;

            return userLogControl;
        }
Exemplo n.º 17
0
 protected static void OnItemSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is CRMMenuControl)
     {
         var topMenuControl = (CRMMenuControl)d;
         if (topMenuControl.ItemSource == null)
             return;
         if (topMenuControl.rootMenuPanel.Children.Count > 0)
         {
             topMenuControl.rootMenuPanel.Children.Clear();
         }
         var topMenuGroupName = Guid.NewGuid().ToString();
         var topMenuEnumerator = topMenuControl.ItemSource.GetEnumerator();
         while (topMenuEnumerator.MoveNext())
         {
             var topMenuButton = new RadioButton()
             {
                 Style = Application.Current.Resources["topMenuButtonStyle"] as Style,
                 DataContext = topMenuEnumerator.Current,
                 GroupName = topMenuGroupName,
                 Margin = new Thickness(0, 0, 1, 0),
                 Padding = new Thickness(10, 5, 10, 1),
                 HorizontalContentAlignment = HorizontalAlignment.Center,
                 VerticalContentAlignment = VerticalAlignment.Center,
                 VerticalAlignment = VerticalAlignment.Center,
                 HorizontalAlignment = HorizontalAlignment.Center
             };
             topMenuButton.SetBinding(RadioButton.ContentProperty, new System.Windows.Data.Binding()
             {
                 Converter = new TopMenuContentValueConverter(),
                 ConverterParameter = topMenuControl.DisplayMemberPath
             });
             topMenuButton.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(topMenuControl.MenuItemButtonClick), true);
             topMenuControl.rootMenuPanel.Children.Add(topMenuButton);
         }
     }
 }
        /// <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);

                    }
                }
            }
        }