Hi all,
I ran across a problem where I'm drawing lines and text blocks on a canvas. When I save the canvas using the XAMLWriter, the lines show up but not the text blocks. I'm opening the XAML file in Inkscape. Some example code below shows what I'm trying to illustrate.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.IO; using System.Windows.Markup; using System.IO.Packaging; namespace ExampleWPF { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); draw(); save(canvas1); } public void draw() { canvas1.Children.Clear(); this.UpdateLayout(); Line myLine = new Line(); myLine.Stroke = System.Windows.Media.Brushes.Black; myLine.X1 = -125.000; myLine.X2 = -135.000; myLine.Y1 = 216.5063509; myLine.Y2 = 233.82685; myLine.StrokeThickness = 1; TextBlock textblock = new TextBlock(); FontFamily family = new FontFamily("Arial"); textblock.Text = "0"; textblock.FontSize = 8; textblock.FontFamily = family ; Canvas.SetLeft(textblock, -145.00000000000003); Canvas.SetTop(textblock, 243.82685); canvas1.Children.Add(myLine); canvas1.Children.Add(textblock); } public void save(Canvas canvas1) { string myXAML = XamlWriter.Save(canvas1); FileStream fs = File.Create("testfile2.xaml"); StreamWriter sw = new StreamWriter(fs); sw.Write(myXAML); sw.Close(); fs.Close(); } private void Button_Click(object sender, RoutedEventArgs e) { draw(); save(canvas1); // this.UpdateLayout(); } } }