wpf - How to build PathGeometry using C#? -


i have following xaml in windows phone 8.1 app running windows runtime:

<canvas name="drawsplice"         grid.row="1"         grid.column="0"         height="80"         width="80"         background="white">          <path stroke="black"                       strokethickness="2"                       data="m 10,10 c 10,50 65,10 65,70" /> </canvas> 

it gives me following shape:

enter image description here

my question how generate such instance of path class using c#?

windows.ui.xaml.shapes.path path = new windows.ui.xaml.shapes.path();  //path.data = "";  path.strokethickness = 3; path.stroke = new solidcolorbrush(colors.black); drawer.children.add(path);  

you can use xamlreader parse , load xaml object string. you'll need full xaml object read in path data, not data itself:

// path data want create string pathxaml = "m 10,10 c 10,50 65,10 65,70";  // xaml container path object. // set other properties stroke , strokethickness string xaml = "<path " + "xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>" + "<path.data>" + pathxaml + "</path.data></path>";  // read xaml string path object windows.ui.xaml.shapes.path path = xamlreader.load(xaml) windows.ui.xaml.shapes.path;  // set other properties skipped above path.strokethickness = 3; path.stroke = new solidcolorbrush(colors.blue);  // add our canvas drawsplice.children.add(path); 

you build path objects. path.data pathgeometry, contains pathfigure (in case one, more), contains pathsegments (in case single beziersegment). using markup easier. see how works can create path markup or xamlloader , examine collections see how it's built up.

note path in xaml doesn't match image included. given xaml path cubic bezier rather ellipse. if want ellipse can use ellipse, or build path ellipsegeometry or arcsegments.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -