Hi Andrej,
check this sample you will get all the problems
Thanks
public partial class Window5 : Window
{
public Window5()
{
InitializeComponent();
LoadViewbox();
//LoadSvg();
canvas.PreviewMouseLeftButtonDown += new
MouseButtonEventHandler(canvas_PreviewMouseLeftButtonDown);
}
void canvas_PreviewMouseLeftButtonDown(object sender,
MouseButtonEventArgs e)
{
for(int i=0;i<canvas.Children.Count;i++)
{
string xaml = System.Windows.Markup.XamlWriter.Save
(canvas.Children[i]);
using (System.IO.MemoryStream stream = new
System.IO.MemoryStream(xaml.Length))
{
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter(stream))
{
sw.Write(xaml);
sw.Flush();
stream.Seek(0, System.IO.SeekOrigin.Begin);
UIElement uie =
System.Windows.Markup.XamlReader.Load(stream) as UIElement;
MessageBox.Show(uie.ToString());
MessageBox.Show("Sucess");
}
}
}
}
public void LoadViewbox()
{
Viewbox viewbox = new Viewbox();
viewbox.Stretch = Stretch.Uniform;
Canvas vieCanvas = new Canvas();
vieCanvas.Width = vieCanvas.Height = 338.5;
Canvas canCanvas = new Canvas();
Path path = new Path();
path.Fill = Brushes.White;
path.Data = StreamGeometry.Parse
("M137.250,227.250L474.750,227.250L474.750,564.750L137.250,564.750L137.250,227.250z");
Path path1 = new Path();
path1.Data = StreamGeometry.Parse
("M208.500,316.500L400.500,316.500L400.500,460.500L208.500,460.500L208.500,316.500z");
ImageBrush imgbr = new ImageBrush();
imgbr.ViewportUnits = BrushMappingMode.Absolute;
imgbr.Viewport = new Rect(0, 0, 800, 600);
imgbr.TileMode = TileMode.Tile;
BitmapImage bitImg = new BitmapImage();
bitImg.DecodePixelHeight = 600;
bitImg.DecodePixelWidth = 800;
bitImg.BeginInit();
bitImg.CacheOption = BitmapCacheOption.OnLoad;
bitImg.UriSource = new Uri(@"C:\Documents and Settings
\User1\Desktop\LDS Export\15-04-09\2.jpg");
bitImg.EndInit();
imgbr.ImageSource = bitImg;
path1.Fill = imgbr;
canCanvas.Children.Add(path);
canCanvas.Children.Add(path1);
vieCanvas.Children.Add(canCanvas);
viewbox.Child = vieCanvas;
canvas.Children.Add(viewbox);
/// its working perfectly why your tool is only giving bug
// <!-- Converted from svg with Ab2d.ReaderSvg.
See
www.wpf-graphics.com for more WPF tools. -->
//<Viewbox xmlns="
http://schemas.microsoft.com/winfx/2006/
xaml/presentation" xmlns:x="
http://schemas.microsoft.com/winfx/2006/
xaml" Stretch="Uniform">
// <Canvas Width="338.5" Height="338.5">
// <Canvas Canvas.Left="-136.75"
Canvas.Top="-226.75">
// <Path Fill="White"
Data="M137.250,227.250L474.750,227.250L474.750,564.750L137.250,564.750L137.250,227.250z"/
>
// <Path
Data="M208.500,316.500L400.500,316.500L400.500,460.500L208.500,460.500L208.500,316.500z">
// <Path.Fill>
// <ImageBrush ViewportUnits="Absolute"
Viewport="0,0,800,600" TileMode="Tile">
// <ImageBrush.ImageSource>
// <BitmapImage
DecodePixelWidth="800" DecodePixelHeight="600" UriSource="C:\Documents
and Settings\User1\Desktop\LDS Export\15-04-09\2.jpg"/>
// </ImageBrush.ImageSource>
// </ImageBrush>
// </Path.Fill>
// </Path>
// </Canvas>
// </Canvas>
//</Viewbox>
}
public void LoadSvg()
{
Ab2d.ReaderSvg myreadersvg;
myreadersvg = new Ab2d.ReaderSvg();
Viewbox vb = myreadersvg.Read(@"C:\Documents and Settings
\User1\Desktop\LDS Export\15-04-09\1.svg");
canvas.Children.Add(vb);
string xaml = System.Windows.Markup.XamlWriter.Save(vb);