Convert path to geometric shape

后端 未结 2 1526
鱼传尺愫
鱼传尺愫 2021-01-05 08:44

Hey everyone I have tried to sum up and come with the basic question and my idea which does not work so far :S

Basicly my question is: The user adds elements togethe

2条回答
  •  礼貌的吻别
    2021-01-05 09:05

    Some time ago, while searching for a solution for this and I ended up creating this function. Maybe it will help you.

        public static Geometry PathMarkupToGeometry(string pathMarkup)
        {
            try
            {
                string xaml =
                "" +
                "" + pathMarkup + "";
                var path = XamlReader.Load(xaml) as Path;
                // Detach the PathGeometry from the Path
                if (path != null)
                {
                    Geometry geometry = path.Data;
                    path.Data = null;
                    return geometry;
                }
                return null;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return null;
        }
    

    Then I call this function like this:

         var arrow = new Path
         {
            Data = DesignHelpers.PathMarkupToGeometry("M-1,0 L0,1 L1,0"),
            Fill = new SolidColorBrush(Colors.Black),
            Stretch = Stretch.Fill,
            Height = 12,
            Width = 18,
            HorizontalAlignment = HorizontalAlignment.Center
        };
    

    I don't know if this will fit your needs exactly but maybe it can help.

提交回复
热议问题