private void RenderLine(Grid grid, int rowCount, string v1, string v2)
        {
            var rowView = new RowDefinition {
                Height = new GridLength(30)
            };

            grid.RowDefinitions.Add(rowView);

            var v1View = new TextBlock
            {
                Text              = v1,
                TextAlignment     = TextAlignment.Right,
                VerticalAlignment = VerticalAlignment.Center,
                Margin            = Thickness.Parse("5")
            };

            Grid.SetRow(v1View, rowCount);
            Grid.SetColumn(v1View, 0);
            grid.Children.Add(v1View);

            var v2View = new TextBox {
                Text = v2
            };

            Grid.SetRow(v2View, rowCount);
            Grid.SetColumn(v2View, 1);
            grid.Children.Add(v2View);
        }
Beispiel #2
0
 private static Border CreateBorderImage(IBitmap source)
 => new Border
 {
     Child = new Image {
         Source = source, Width = 128, Height = 128, Margin = Thickness.Parse("4")
     }
 };
        public FluentWindow()
        {
            ExtendClientAreaToDecorationsHint  = true;
            ExtendClientAreaTitleBarHeightHint = -1;
            FontFamily.Parse("avares://InDepthSearch/Assets/Fonts#Roboto");

            TransparencyLevelHint = WindowTransparencyLevel.AcrylicBlur;

            this.GetObservable(WindowStateProperty)
            .Subscribe(x =>
            {
                PseudoClasses.Set(":maximized", x == WindowState.Maximized);
                PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen);
                if (x == WindowState.Maximized)
                {
                    Padding = Thickness.Parse("8");                                 // https://github.com/AvaloniaUI/Avalonia/issues/5581
                }
                else
                {
                    Padding = Thickness.Parse("0");
                }
            });

            this.GetObservable(IsExtendedIntoWindowDecorationsProperty)
            .Subscribe(x =>
            {
                if (!x)
                {
                    SystemDecorations     = SystemDecorations.Full;
                    TransparencyLevelHint = WindowTransparencyLevel.Blur;
                }
            });
        }
        /// <summary>
        /// Retrieves a list of identities and pupulates the user interface.
        /// </summary>
        private void PopulateUI()
        {
            _stackPnlMain = this.FindControl <StackPanel>("stackPnlMain");
            var currentId         = _identityManager.CurrentIdentity;
            var currentIdUniqueId = _identityManager.CurrentIdentityUniqueId;
            var ids = _identityManager.GetIdentities();

            Controls content = _stackPnlMain.Children;

            content.Clear();

            foreach (var id in ids)
            {
                string name     = id.Item1;
                string uniqueId = id.Item2;

                RadioButton rb = new RadioButton()
                {
                    Content = name,
                    Margin  = Thickness.Parse("20,10,20,10"),
                    Tag     = id
                };

                if (currentIdUniqueId == uniqueId)
                {
                    rb.IsChecked = true;
                }

                rb.Click += OnIdentitySelected;

                content.Add(rb);
            }
        }
Beispiel #5
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (objectType == typeof(ThicknessViewModel))
     {
         return(Thickness.Parse((string)reader.Value).FromThickness());
     }
     throw new ArgumentException("objectType");
 }
Beispiel #6
0
        public static void FromTextString(this string value, out double left, out double top, out double right, out double bottom)
        {
            var thickness = Thickness.Parse(value);

            left   = thickness.Left;
            top    = thickness.Top;
            right  = thickness.Right;
            bottom = thickness.Bottom;
        }
Beispiel #7
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonObject      = serializer.Deserialize <JObject>(reader);
            var paddingAsString = jsonObject.Value <string>("Padding");
            var thickness       = Thickness.Parse(paddingAsString);
            var regionName      = jsonObject.Value <string>("TextureRegion");
            var region          = _textureRegionService.GetTextureRegion(regionName);

            return(new NinePatchRegion2D(region, thickness.Left, thickness.Top, thickness.Right, thickness.Bottom));
        }
Beispiel #8
0
        public void A()
        {
            var a = Thickness.Parse("10px 20%");

            Assert.Equal("10px", a.Top.ToString());
            Assert.Equal("20%", a.Left.ToString());
            Assert.Equal("10px", a.Bottom.ToString());
            Assert.Equal("20%", a.Right.ToString());

            Assert.Equal("10px 20% 10px 20%", a.ToString());
        }
        public MainWindow()
        {
            InitializeComponent();
            TextBlock block = new TextBlock();

            block.Text = "Lorem";
            StackPanel panel = new StackPanel();

            panel.Children.Add(block);

            Button b = new Button();

            b.Content    = "Szia";
            b.Background = Brushes.LightSkyBlue;
            Button b2 = new Button();

            b2.Content = "Dolgozo Hozzáadása";
            b2.Name    = "btn2";
            b2.Click  += formMegnyitasa;

            Grid grid = new Grid();

            grid.Width         = 500;
            grid.Background    = Brushes.Beige;
            grid.Margin        = Thickness.Parse("20,10,20,10");
            grid.ShowGridLines = true;
            ColumnDefinition column1 = new ColumnDefinition(GridLength.Parse("2*"));
            ColumnDefinition column2 = new ColumnDefinition(GridLength.Parse("*"));

            grid.ColumnDefinitions.Add(column1);
            grid.ColumnDefinitions.Add(column2);
            RowDefinition row = new RowDefinition();

            grid.RowDefinitions.Add(row);
            Grid.SetColumn(b, 0);
            Grid.SetColumn(b2, 1);
            grid.Children.Add(b);
            grid.Children.Add(b2);

            panel.Children.Add(grid);
            WrapPanel root = this.Find <WrapPanel>("wrappanel");

            root.Orientation = Orientation.Vertical;
            root.Children.Add(panel);
            NameScope scope = new NameScope();

            b2.RegisterInNameScope(scope);
            root.RegisterInNameScope(scope);
            Button sayhibutton = this.Find <Button>("sayhibutton");

            sayhibutton.RegisterInNameScope(scope);
            sayhibutton.Click += sayhi;
            NameScope.SetNameScope(this, scope);
        }
Beispiel #10
0
 public void DrawText(string text, TextFormatter formatter, out TextBox textBox)
 {
     textBox = new TextBox()
     {
         Text            = text,
         FontSize        = formatter.FontSize,
         Foreground      = formatter.FontColor,
         IsReadOnly      = true,
         BorderThickness = Thickness.Parse(formatter.BorderSize),
         BorderBrush     = Brushes.Black
     };
     Canvas.Children.Add(textBox);
     SetPosition(textBox, formatter.Position.X, formatter.Position.Y);
 }
Beispiel #11
0
        public override void Import(ImportFile file)
        {
            MetaDefinition meta     = null;
            var            yamlPath = Path.ChangeExtension(file.Filename, ".yaml");

            if (File.Exists(yamlPath))
            {
                using (var yamlStream = File.OpenRead(yamlPath))
                    using (var yamlReader = new StreamReader(yamlStream))
                    {
                        meta = (new YamlDotNet.Serialization.Deserializer()).Deserialize <MetaDefinition>(yamlReader);
                    }
            }

            var border = Thickness.Empty;

            if (meta != null && meta.Image != null)
            {
                border = Thickness.Parse(meta.Image.Border);
            }

            if (meta != null && meta.ImageAtlas != null)
            {
                var targetPath = Path.ChangeExtension(file.TargetFilename, null);

                // Create a directory with the same name as the resource
                Directory.CreateDirectory(targetPath);

                for (var i = 0; i < meta.ImageAtlas.Images.Length; i++)
                {
                    using (var sourceFile = File.OpenRead(file.Filename))
                        using (var targetWriter = new ResourceWriter(File.OpenWrite($"{targetPath}/{meta.ImageAtlas.Images[i].Name}.resource"), typeof(Image)))
                            Import(sourceFile, targetWriter, border,
                                   new SixLabors.Primitives.Rectangle(
                                       meta.ImageAtlas.Images[i].Rect.x,
                                       meta.ImageAtlas.Images[i].Rect.y,
                                       meta.ImageAtlas.Images[i].Rect.w,
                                       meta.ImageAtlas.Images[i].Rect.h));

                    // TODO: write the atlas out as a resource
                }
            }
            else
            {
                using (var sourceFile = File.OpenRead(file.Filename))
                    using (var targetWriter = new ResourceWriter(File.OpenWrite(file.TargetFilename), typeof(NoZ.Image)))
                        Import(sourceFile, targetWriter, border, SixLabors.Primitives.Rectangle.Empty);
            }
        }
Beispiel #12
0
#pragma warning restore CA1822 // 将成员标记为 static

        public IControl Build(object data)
        {
            var name = data.GetType().FullName?.Replace("ViewModel", "View");
            var type = name == null ? null : Type.GetType(name);

            if (type != null)
            {
                var view = (Control?)Activator.CreateInstance(type);
                if (view != null)
                {
                    return(view);
                }
            }
            return(new TextBlock {
                Text = "Not Found: " + name, Padding = Thickness.Parse("24, 4, 24, 24"), FontWeight = FontWeight.Bold, FontSize = 22,
            });
        }
Beispiel #13
0
        public void Process(ParserContext context)
        {
            var textValue  = context.CurrentElement["Fill"];
            var paddingVal = context.CurrentElement["Fill-Padding"];
            var padding    = paddingVal == null ? new Thickness() : Thickness.Parse(paddingVal);

            if (textValue == "Horizontal")
            {
                context.CurrentControl.FillHoriontally(padding: padding);
            }
            else if (textValue == "Vertical")
            {
                context.CurrentControl.FillVertically(padding: padding);
            }
            else if (textValue == "Both")
            {
                context.CurrentControl.Fill(padding: padding);
            }
        }
Beispiel #14
0
        private object ConvertPropertyType(Type targetType, string value)
        {
            if (targetType.IsEnum)
            {
                return(Enum.Parse(targetType, value, true));
            }

            if (targetType == typeof(Size))
            {
                return(Size.Parse(value));
            }

            if (targetType == typeof(Thickness))
            {
                return(Thickness.Parse(value));
            }

            if (targetType == typeof(int))
            {
                return(int.Parse(value));
            }

            if (targetType == typeof(double))
            {
                return(double.Parse(value));
            }

            if (targetType == typeof(float))
            {
                return(float.Parse(value));
            }

            if (targetType == typeof(bool))
            {
                return(bool.Parse(value));
            }

            return(Convert.ChangeType(value, targetType));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BorderPresence val = (BorderPresence)value;

            string[] radiusStrings = parameter.ToString().Split(';');
            if (radiusStrings.Length == 2)
            {
                Thickness trueRadius  = Thickness.Parse(radiusStrings[0]);
                Thickness falseRadius = Thickness.Parse(radiusStrings[1]);

                double retLeft   = trueRadius.Left;
                double retTop    = trueRadius.Right;
                double retRight  = trueRadius.Right;
                double retBottom = trueRadius.Bottom;

                if (!val.Left)
                {
                    retLeft = falseRadius.Left;
                }

                if (!val.Top)
                {
                    retTop = falseRadius.Top;
                }

                if (!val.Right)
                {
                    retRight = falseRadius.Right;
                }

                if (!val.Bottom)
                {
                    retBottom = falseRadius.Bottom;
                }

                return(new Thickness(retLeft, retTop, retRight, retBottom));
            }
            throw new InvalidOperationException("Invalid parameter value.");
        }
Beispiel #16
0
        public void SetControl(Control control, int timeout = 0)
        {
            Root.Children.Clear();

            if (control != null)
            {
                control.Margin = Thickness.Parse("40 20");

                Root.Children.Add(control);
                IsHitTestVisible = true;
                Opacity          = 1;

                if (timeout > 0)
                {
                    Task.Delay(timeout).ContinueWith(_ => Dispatcher.UIThread.InvokeAsync(() => IsVisible = false));
                }
            }
            else
            {
                IsHitTestVisible = false;
                Opacity          = 0;
            }
        }
Beispiel #17
0
        /// <summary>
        /// </summary>
        /// <param name="image"> </param>
        /// <param name="name"> </param>
        /// <returns> </returns>
        public static StackPanel ImageHeader(Bitmap img, string name)
        {
            var stackPanel = new StackPanel {
                Orientation = Orientation.Horizontal
            };
            var image = new Image {
                Width = 24, Height = 24, [ToolTip.TipProperty] = name, Source = img
            };
            var label = new TextBlock {
                Name = "TheLabel", Text = name, VerticalAlignment = VerticalAlignment.Center, Margin = Thickness.Parse("5,0,0,0")
            };

            stackPanel.Children.Add(image);
            stackPanel.Children.Add(label);
            return(stackPanel);
        }
Beispiel #18
0
        public void Parse_Accepts_Spaces()
        {
            var result = Thickness.Parse("1.2 3.4 5 6");

            Assert.Equal(new Thickness(1.2, 3.4, 5, 6), result);
        }
Beispiel #19
0
        public void Parse_Parses_Left_Top_Right_Bottom()
        {
            var result = Thickness.Parse("1.2, 3.4, 5, 6");

            Assert.Equal(new Thickness(1.2, 3.4, 5, 6), result);
        }
Beispiel #20
0
        public void Parse_Parses_Horizontal_Vertical()
        {
            var result = Thickness.Parse("1.2,3.4");

            Assert.Equal(new Thickness(1.2, 3.4), result);
        }
Beispiel #21
0
        public void Parse_Parses_Single_Uniform_Size()
        {
            var result = Thickness.Parse("1.2");

            Assert.Equal(new Thickness(1.2), result);
        }
Beispiel #22
0
        public void Parse_Parses_Horizontal_Vertical()
        {
            var result = Thickness.Parse("1.2,3.4", CultureInfo.InvariantCulture);

            Assert.Equal(new Thickness(1.2, 3.4), result);
        }
        public static bool TryConvert(AstTransformationContext context, IXamlAstValueNode node, string text, IXamlType type, AvaloniaXamlIlWellKnownTypes types, out IXamlAstValueNode result)
        {
            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                try
                {
                    var thickness = Thickness.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor,
                                                                         new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node);
                }
            }

            if (type.Equals(types.Point))
            {
                try
                {
                    var point = Point.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                         new[] { point.X, point.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node);
                }
            }

            if (type.Equals(types.Vector))
            {
                try
                {
                    var vector = Vector.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                         new[] { vector.X, vector.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node);
                }
            }

            if (type.Equals(types.Size))
            {
                try
                {
                    var size = Size.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                         new[] { size.Width, size.Height });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node);
                }
            }

            if (type.Equals(types.Matrix))
            {
                try
                {
                    var matrix = Matrix.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor,
                                                                         new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node);
                }
            }

            if (type.Equals(types.CornerRadius))
            {
                try
                {
                    var cornerRadius = CornerRadius.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor,
                                                                         new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node);
                }
            }

            if (type.Equals(types.Color))
            {
                if (!Color.TryParse(text, out Color color))
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node);
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.GetMethod(
                                                                          new FindMethodMethodSignature("FromUInt32", type, types.UInt)
                {
                    IsStatic = true
                }),
                                                                      new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) });

                return(true);
            }

            if (type.Equals(types.GridLength))
            {
                try
                {
                    var gridLength = GridLength.Parse(text);

                    result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength);

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node);
                }
            }

            if (type.Equals(types.Cursor))
            {
                if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode))
                {
                    var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false);

                    result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List <IXamlAstValueNode> {
                        enumConstantNode
                    });

                    return(true);
                }
            }

            if (type.Equals(types.ColumnDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.ColumnDefinitions, types.ColumnDefinition, "column definitions", out result));
            }

            if (type.Equals(types.RowDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.RowDefinitions, types.RowDefinition, "row definitions", out result));
            }

            if (type.Equals(types.Classes))
            {
                var classes    = text.Split(' ');
                var classNodes = classes.Select(c => new XamlAstTextNode(node, c, types.XamlIlTypes.String)).ToArray();

                result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, types.Classes, types.XamlIlTypes.String, classNodes);
                return(true);
            }

            result = null;
            return(false);
        }
Beispiel #24
0
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text = textNode.Text;

            var types = context.GetAvaloniaTypes();

            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }


                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                var thickness = Thickness.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor,
                                                                     new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom });

                return(true);
            }

            if (type.Equals(types.Point))
            {
                var point = Point.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                     new[] { point.X, point.Y });

                return(true);
            }

            if (type.Equals(types.Vector))
            {
                var vector = Vector.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                     new[] { vector.X, vector.Y });

                return(true);
            }

            if (type.Equals(types.Size))
            {
                var size = Size.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                     new[] { size.Width, size.Height });

                return(true);
            }

            if (type.Equals(types.Matrix))
            {
                var matrix = Matrix.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor,
                                                                     new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 });

                return(true);
            }

            if (type.Equals(types.CornerRadius))
            {
                var cornerRadius = CornerRadius.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor,
                                                                     new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft });

                return(true);
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }

                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node);
                return(true);
            }

            result = null;
            return(false);
        }
Beispiel #25
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(Thickness.Parse((string)value));
 }
Beispiel #26
0
        public void Parse_Accepts_Spaces()
        {
            var result = Thickness.Parse("1.2 3.4 5 6", CultureInfo.InvariantCulture);

            Assert.Equal(new Thickness(1.2, 3.4, 5, 6), result);
        }
Beispiel #27
0
        public object Convert(IList <object> values, Type targetType, object parameter, CultureInfo culture)
        {
            double    offsetL = 4, offsetR = 4;
            Thickness t = new Thickness(4, 0);

            if (parameter != null)
            {
                try
                {
                    t = Thickness.Parse(parameter.ToString());
                }
                catch
                {
                    // ignored
                }
            }

            Rect main   = Rect.Empty;
            Rect hollow = Rect.Empty;

            StreamGeometry result = null;

            try
            {
                Point s = new Point(1, 1);

                if ((values[0] is Rect mainR))
                {
                    main = mainR;
                }
                if ((values[1] is Rect hollowR))
                {
                    hollow = hollowR;
                }
                if ((values[2] is TransformedBounds tb))
                {
                    s = new Point(tb.Transform.M11, tb.Transform.M22);
                }

                // Base zone
                var m0 = main.TopLeft;
                var m1 = main.BottomRight;

                // Hollow zone
                var h0 = hollow.TopLeft + new Point(offsetL - t.Left, 0);
                var h1 = hollow.BottomRight + new Point(offsetR + t.Right, 0);

                // Limiter
                var lL = main.Left - t.Left + offsetL;
                var lR = main.Right + t.Right + offsetR;

                var str = $"M {m0.X} {m0.Y} " +
                          $"L {m1.X} {m0.Y} " +
                          $"L {m1.X} {m1.Y} " +
                          $"L {m0.X} {m1.Y} z " +
                          $"M {Math.Max(h0.X * s.X, lL)} {h0.Y * s.Y} " +
                          $"L {Math.Min(h1.X * s.X, lR)} {h0.Y * s.Y} " +
                          $"L {Math.Min(h1.X * s.X, lR)} {h1.Y * s.Y} " +
                          $"L {Math.Max(h0.X * s.X, lL)} {h1.Y * s.Y} z ";

                str = str.Replace(",", ".");

                result = StreamGeometry.Parse(str);
            }
            catch (Exception e)
            {
                var m0 = main.TopLeft;
                var m1 = main.BottomRight;

                result = StreamGeometry.Parse($"M {m0.X} {m0.Y} " +
                                              $"L {m1.X} {m0.Y} " +
                                              $"L {m1.X} {m1.Y} " +
                                              $"L {m0.X} {m1.Y} z ");
            }

            return(result);
        }
Beispiel #28
0
        public void Parse_Parses_Single_Uniform_Size()
        {
            var result = Thickness.Parse("1.2", CultureInfo.InvariantCulture);

            Assert.Equal(new Thickness(1.2), result);
        }
Beispiel #29
0
 public static void SetPopupPadding(ComboBox comboBox, string value) =>
 comboBox.SetValue(PopupPaddingProperty, Thickness.Parse(value));
Beispiel #30
0
 public void Deserialize(XmlElement element)
 {
     Border          = Thickness.Parse(element.GetAttribute("Border"));
     NormalRectangle = element.GetAttribute("NormalRectangle").ParseRectangle();
 }