SvgViewbox Class |
Namespace: Ab2d.Controls
public class SvgViewbox : Viewbox, IUriContext, ISupportInitialize
The SvgViewbox type exposes the following members.
Name | Description | |
---|---|---|
SvgViewbox |
Constructor for SvgViewbox.
|
Name | Description | |
---|---|---|
AutoSize |
If true (default) the size of main canvas is calculated from the size of all inner objects. This means that the returned objects will be just as big as its contain objects.
If false the size of svg element is used for the size of main canvas. This is useful for example if you were working on a Letter area and would like to preserve the position of objects inside the Letter.
| |
InnerReaderSvg |
Gets the ReaderSvg that was used to read the svg file. Useful to get the properties of ReaderSvg for example NamedObjects (gets the names of objects as defined in svg file)
| |
NamedObjects |
Dictionary defined from elements in svg file. Elements ids are keys and its appropriate objects are values.
| |
NamedObjectsSource |
Gets or sets one of the ReaderSvgNamedObjectsSourceType as the source to get the object's name. Default value is NamedObjectsSourceType.Auto.
| |
Source |
Source or the svg or svgz image.
| |
SourceStream |
Stream that is used to read svg file. When this property is set (not null) it is used instead of Source property.
|
Name | Description | |
---|---|---|
OnCreateAutomationPeer | Returns class-specific AutomationPeer implementations for the Windows Presentation Foundation (WPF) infrastructure. (Overrides UIElementOnCreateAutomationPeer.) | |
OnSvgFileLoaded |
OnSvgFileLoaded is called after the svg file has been read. The method can be overriden in derived class.
| |
OnSvgFileLoading |
OnSvgFileLoading is called before the svg file is read. The method can be overridden in derived class.
| |
ReadSvg(Uri) | Obsolete.
Reads svg file from sourceUri. This method can be overridden to provide reading svg files from some other source.
| |
ReadSvg(Uri, Stream) |
Reads svg file from sourceUri or sourceStream.
This method can be overridden to provide reading svg files from some other source.
|
Name | Description | |
---|---|---|
SvgFileLoaded |
Occurs when the reading of svg file is completed.
| |
SvgFileLoading |
Occurs before the reading of svg file is started.
|
Name | Description | |
---|---|---|
AutoSizeProperty |
AutoSizeProperty
| |
SourceProperty |
SourceProperty
| |
SourceStreamProperty |
SourceProperty
|
SvgViewbox is using ReaderSvg library to read the svg file and convert it into WPF elements.
To read the svg file set Source or SourceStream property. It supports the Pack URI (see also "http://msdn2.microsoft.com/en-us/library/aa970069.aspx#Site_of_Origin_File_Pack_URIs"). Here are some of the example Sources that can be used to read svg file from various locations:
URI string | Description |
---|---|
Subfolder/ResourceFile.svg | Reads ResourceFile.svg from the application resources (embeded in the assembly) under Subfolder - set the file's Build Action to Resource |
pack://application:,,,/Subfolder/ResourceFile.svg | Same as previous but this time with full pack URI |
ContentFile.svg | Reads ContentFile.svg from the same folder as the application is running - set the file's Build Action to Content |
pack://application:,,,/ReferencedAssembly;component/ResourceFile.svg | Reads ResourceFile.svg from the ReferencedAssembly resources. |
pack://siteoforigin:,,,/File.svg | Reads File.svg from the same folder as the application is running - this is a loose file that means it is not included in the project |
c:\images\File.svg | Reads File.svg from the specified file on the disk |
http://www.mysite.com/images/File.svg | Reads File.svg from specified url location |
When using in code create new Uri with on of the above strings and set it to Source property.
The following example shows how to use SvgViewbox xaml.
<ab2d:SvgViewbox Source="Images/MyImage.svg" Width="200" Height="100"/>
The following example shows how to use SvgViewbox in code:
var mySvgImage = new Ab2d.Controls.SvgViewbox(); mySvgImage.Source = new Uri("Images/MyImage.svg"); mySvgImage.Width = 200; mySvgImage.Height = 100; myStackPanel.Controls.Add(mySvgImage);
The following example shows how to read svg file from stream:
var streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/Resources/home1.svg")); if (streamResourceInfo != null) { var mySvgImage = new Ab2d.Controls.SvgViewbox(); mySvgImage.SourceStream = streamResourceInfo.Stream; mySvgImage.Width = 200; mySvgImage.Height = 100; myStackPanel.Controls.Add(mySvgImage); }