Inheritance: System.Windows.Controls.ContentControl
Example #1
0
        private static void OnRenderPressedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ButtonChrome buttonChrome = o as ButtonChrome;

            if (buttonChrome != null)
            {
                buttonChrome.OnRenderPressedChanged(( bool )e.OldValue, ( bool )e.NewValue);
            }
        }
Example #2
0
        private static void OnInnerCornerRadiusChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ButtonChrome buttonChrome = o as ButtonChrome;

            if (buttonChrome != null)
            {
                buttonChrome.OnInnerCornerRadiusChanged(( CornerRadius )e.OldValue, ( CornerRadius )e.NewValue);
            }
        }
Example #3
0
        private void AddMeasures()
        {
            foreach (var measurement in _measurements)
            {
                var line = new Line
                {
                    Stroke = new SolidColorBrush(Colors.Yellow),
                    StrokeThickness = 2,
                    X1 = measurement.StartPoint.X - (4 * ScrollPosition),
                    Y1 = measurement.StartPoint.Y,
                    X2 = measurement.EndPoint.X - (4 * ScrollPosition),
                    Y2 = measurement.EndPoint.Y
                };

                Panel.SetZIndex(line, 2);
                ControlCanvas.Children.Add(line);

                var startPoint = new Point(line.X1, line.Y1);
                var endPoint = new Point(line.X2, line.Y2);
                var v = startPoint - endPoint;
                var midpoint = endPoint + (v / 2);
                var theta = Math.Atan2(v.Y, v.X);
                var offset = Math.PI / 2;
                if (v.Y > 0)
                    offset = -Math.PI / 2;

                var theta2 = theta + offset;
                var x4 = 10 * Math.Cos(theta2) + midpoint.X;
                var y4 = 10 * Math.Sin(theta2) + midpoint.Y;

                var x3 = 30 * Math.Cos(theta2) + midpoint.X;
                var y3 = 30 * Math.Sin(theta2) + midpoint.Y;

                var redline = new Line
                {
                    Stroke = new SolidColorBrush(Colors.Yellow),
                    X1 = x4,
                    Y1 = y4,
                    X2 = x3,
                    Y2 = y3,
                    StrokeThickness = 2
                };

                // anchor points
                AddAnchor(startPoint);
                AddAnchor(endPoint);

                var panel = new StackPanel();
                var outerBorder = new Border
                {
                    Background = new SolidColorBrush(Color.FromArgb(0xa2, 0xaf, 0x2a, 0x2a)),
                    CornerRadius = new CornerRadius(4),
                };

                var innerBorder = new Border
                {
                    Margin = new Thickness(4),
                    Background = new SolidColorBrush(Color.FromArgb(0xa2, 0xf2, 0xda, 0xc7)),
                    CornerRadius = new CornerRadius(4)
                };

                panel.Children.Add(outerBorder);
                outerBorder.Child = innerBorder;

                var grid = new Grid { Margin = new Thickness(5) };
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                var rowDefinition = new RowDefinition();
                rowDefinition.Height = new GridLength(1, GridUnitType.Auto);

                grid.RowDefinitions.Add(rowDefinition);
                grid.RowDefinitions.Add(new RowDefinition());
                grid.RowDefinitions.Add(new RowDefinition());

                var voltageLabel = new Label { Foreground = new SolidColorBrush(Colors.Brown), Margin = new Thickness(0, 0, 2, 0), Content = "Voltage:", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 10.0 };
                var voltageValueLabel = new Label { FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White), Content = measurement.VoltageMeasure, VerticalAlignment = VerticalAlignment.Center, FontSize = 10.0 };
                var timeLabel = new Label { Foreground = new SolidColorBrush(Colors.Brown), Margin = new Thickness(0, 0, 2, 0), Content = "Time:", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, FontSize = 10.0 };
                var timeValueLabel = new Label { FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.White), Content = measurement.TimeMeasure, VerticalAlignment = VerticalAlignment.Center, FontSize = 10.0 };

                var button = new ButtonChrome();
                button.Content = "X";
                button.HorizontalAlignment = HorizontalAlignment.Right;
                button.FontSize = 10.0;
                button.Padding = new Thickness(4);
                button.CornerRadius = new CornerRadius(4);

                button.Cursor = Cursors.Hand;

                button.MouseDown += ButtonOnMouseDown;

                Grid.SetColumn(voltageValueLabel, 1);
                Grid.SetColumn(timeValueLabel, 1);

                Grid.SetRow(voltageLabel, 1);
                Grid.SetRow(voltageValueLabel, 1);

                Grid.SetRow(timeLabel, 2);
                Grid.SetRow(timeValueLabel, 2);

                Grid.SetColumn(button, 1);

                var title = new Label();
                title.Content = "Measurement";
                title.FontSize = 10;
                title.HorizontalAlignment = HorizontalAlignment.Right;
                title.Foreground = new SolidColorBrush(Colors.White);
                title.FontWeight = FontWeights.Bold;

                grid.Children.Add(title);
                grid.Children.Add(voltageLabel);
                grid.Children.Add(voltageValueLabel);
                grid.Children.Add(timeLabel);
                grid.Children.Add(timeValueLabel);
                grid.Children.Add(button);

                innerBorder.Child = grid;

                panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                var top = y3;
                if ((endPoint.X <= startPoint.X && endPoint.Y <= startPoint.Y) || (endPoint.X >= startPoint.X && endPoint.Y >= startPoint.Y))
                {
                    top -= panel.DesiredSize.Height;
                }

                Panel.SetZIndex(panel, 1);
                Canvas.SetLeft(panel, x3);
                Canvas.SetTop(panel, top);

                var polyLineArrowHead = AddArrowHead(midpoint, theta2);

                ControlCanvas.Children.Add(redline);
                ControlCanvas.Children.Add(polyLineArrowHead);
                ControlCanvas.Children.Add(panel);
            }
        }