Click or drag to resize
ReaderWmfGetXaml Method
Gets xaml of the last read metafile.
Overload List
  NameDescription
Public methodCode exampleGetXaml
Gets xaml of the last read metafile with the default setting for WPF.
Public methodCode exampleGetXaml(BaseXamlWriterSettings)
Gets xaml of the last read metafile.
Top
Remarks

Read or ReadGeometry must be called before using GetXaml.

To specify detailed options for xaml or to get xaml for Silverlight use GetXaml method.

Examples
The following sample reads the mySample.wmf file, gets its xaml (for WPF) and saves it into a file.
string xaml;
Viewbox sampleViewbox;

sampleViewbox = myReader.Read(@"c:\mySample.wmf");
xaml = myReader.GetXaml();

System.IO.File.WriteAllText(@"c:\mySample.xaml", xaml);
The following sample reads the mySample.wmf file, gets its xaml for Silverlight and saves it into a file.
string xaml;
Viewbox sampleViewbox;

sampleViewbox = myReader.Read(@"c:\mySample.wmf");
xaml = myReader.GetXaml(new Ab2d.Common.ReaderWmf.SilverlightXamlWriterSettings());

System.IO.File.WriteAllText(@"c:\mySample_for_Silverlight.xaml", xaml);

The GetXaml method by default writes image uri-s as "image_0", "image_1", and so on. With ResolveImagePathDelegate it is possible to control the image uri of each of the used images. The following code reads the metafile, saves the images to disk and creates xaml text with image uri-s that point to saved images.

// Use the code with:
// string xamlText = GetXamlWithImages("images_test.emf", @"c:\temp\image_{0}.{1}");

private string GetXamlWithImages(string metaFileName, string imageFormatString)
{
    string xamlText;
    int imagesCount;
    Ab2d.ReaderWmf myReaderWmf;
    Ab2d.Common.ReaderWmf.WpfXamlWriterSettings xamlSettings;


    // Read the svg file
    myReaderWmf = new Ab2d.ReaderWmf();
    myReaderWmf.Read(metaFileName);

    if (myReaderWmf.EmbeddedBitmapImages != null)
    {
        imagesCount = myReaderWmf.EmbeddedBitmapImages.Count;

        for (int i = 0; i < imagesCount; i++)
        {
            string oneFileName;
            EmbeddedImageData oneImageData;

            oneImageData = myReaderWmf.EmbeddedImagesData[i];
            oneFileName = string.Format(imageFormatString, i, oneImageData.ImageFileExtention);

            System.IO.File.WriteAllBytes(oneFileName, oneImageData.Data);
        }
    }

    xamlSettings = new Ab2d.Common.ReaderWmf.WpfXamlWriterSettings();
    xamlSettings.DefaultImageUriFormatString = imageFormatString;

    xamlText = myReaderWmf.GetXaml(xamlSettings);

    return xamlText;
}
See Also