0

I want to set a Data for a Path (UIElement) and I used these code:

string arrSound =  "M153.1,2.6L54.5,74.9H15.9C7.1,74.9,0,82.3,0,91.3v43.7c0,9,7.2,16.4,15.9,16.4h38.5l98.7,72.3"+
        "c7.2,5.3,12.9,2.2,12.9-6.8V9.4C166.1,0.4,160.3-2.7,153.1,2.6L153.1,2.6z M153.1,2.6 M269.1,113.7l37.2-38.2c3.1-3.2,3.1-8.5,0-11.6l-7.5-7.7c-3.1-3.2-8.2-3.2-11.3,0l-37.2,38.2l-36.9-37.9"+
        "c-3.1-3.2-8.2-3.2-11.3,0l-7.5,7.7c-3.1,3.2-3.1,8.5,0,11.6l36.9,37.9l-36.9,37.9c-3.1,3.2-3.1,8.5,0,11.6l7.5,7.7"+
        "c3.1,3.2,8.2,3.2,11.3,0l36.9-37.9l36.9,37.9c3.1,3.2,8.2,3.2,11.3,0l7.5-7.7c3.1-3.2,3.1-8.5,0-11.6L269.1,113.7z M269.1,113.7";

string frontCode = "<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Data='";

System.Windows.Shapes.Path geo;
geo = XamlReader.Load(frontCode + arrSound + "'/>") as System.Windows.Shapes.Path;
vectorSound.Data = geo.Data;

But when I ran into this line vectorSound.Data = geo.Data an error appeared.

Smern
  • 18,746
  • 21
  • 72
  • 90
iamatsundere181
  • 1,401
  • 1
  • 16
  • 38

1 Answers1

0

It should work if you just parse a XAML Geometry:

var xaml = "<Geometry xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">"
    + arrSound + "</Geometry>";

vectorSound.Data = (Geometry)XamlReader.Load(xaml);
Clemens
  • 123,504
  • 12
  • 155
  • 268