Click or drag to resize
ReaderWmfGetXaml Method (BaseXamlWriterSettings)
Gets xaml of the last read metafile.

Namespace: Ab2d
Assembly: Ab2d.ReaderWmf (in Ab2d.ReaderWmf.dll) Version: 7.1.5512.1040
Syntax
C#
public string GetXaml(
	BaseXamlWriterSettings settings
)

Parameters

settings
Type: Ab2d.Common.ReaderWmfBaseXamlWriterSettings
XamlWriterSettings that define advanced options for xaml writer. To get xaml for WPF, use Ab2d.Common.ReaderWmf.WpfXamlWriterSettings. For Silverlight use Ab2d.Common.ReaderWmf.SilverlightXamlWriterSettings.

Return Value

Type: String
xaml of the last read metafile
Remarks

Read or ReadGeometry must be called before using GetXaml.

To get xaml for WPF, use Ab2d.Common.ReaderWmf.WpfXamlWriterSettings. For Silverlight use Ab2d.Common.ReaderWmf.SilverlightXamlWriterSettings.

Examples
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.png", "image_1.jpg", and so on. The default format for the uri is controlled by DefaultImageUriFormatString. 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