SvgDrawing Class |
Namespace: Ab2d.Controls
public class SvgDrawing : FrameworkElement, IUriContext, ISupportInitialize
The SvgDrawing type exposes the following members.
Name | Description | |
---|---|---|
SvgDrawing |
Constructor
|
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.
| |
InnerImage |
Gets the Image returned by last read with ReaderSvg.
| |
InnerReaderSvg |
Gets the ReaderSvg that was used to read the svg or svgz file.
| |
NamedObjectsSource |
Gets or sets one of the ReaderSvgNamedObjectsSourceType as the source to get the object's name. Default value is NamedObjectsSourceType.Auto.
| |
OptimizationPercent |
Gets or sets the geometry optimization percent. 0 means no optimization, 100 means full optimization.
| |
Source |
Gets or sets the Source of the svg or svgz file
| |
SourceStream |
Stream that is used to read svg file. When this property is set (not null) it is used instead of Source property.
| |
Stretch |
Gets or sets the SvgDrawing.Windows.Media.Stretch
mode, which determines how content fits into the available space.
| |
StretchDirection |
Gets or sets the System.Windows.Controls.StretchDirection, which determines
how scaling is applied to the contents of a SvgDrawing.
|
Name | Description | |
---|---|---|
ArrangeOverride | When overridden in a derived class, positions child elements and determines a size for a FrameworkElement derived class. (Overrides FrameworkElementArrangeOverride(Size).) | |
MeasureOverride | When overridden in a derived class, measures the size in layout required for child elements and determines a size for the FrameworkElement-derived class. (Overrides FrameworkElementMeasureOverride(Size).) | |
OnCreateAutomationPeer |
OnCreateAutomationPeer
(Overrides UIElementOnCreateAutomationPeer.) | |
OnRender |
OnRender
(Overrides UIElementOnRender(DrawingContext).) | |
OnSvgFileLoaded |
OnSvgFileLoaded is called after the svg file has been read. The method can be overridden in derived class.
| |
OnSvgFileLoading |
OnSvgFileLoading is called before the svg file is read. The method can be overridden in derived class.
| |
ReadSvg(Uri, Int32) | Obsolete.
Reads svg or svgz file from sourceUri and with optimizationPercent
| |
ReadSvg(Uri, Stream, Int32) |
Reads svg file from sourceUri or sourceStream and with the specified optimizationPercent
|
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
| |
OptimizationPercentProperty |
OptimizationPercentProperty
| |
SourceProperty |
SourceProperty
| |
SourceStreamProperty |
SourceProperty
| |
StretchDirectionProperty |
StretchDirectionProperty
| |
StretchProperty |
StretchProperty
|
The difference between SvgDrawing and SvgViewbox is that SvgViewbox gets objects as Shapes (Canvas, Path, Polyline, etc) and SvgDrawing produces Drawings (DrawingGeometry, StreamGeometry, etc). Drawings have better performance and lower memory consumption, but Shapes support more functionality - layout, focus, mouse events, etc.
For more information about reading geometers see ReadGeometry(String, GeometrySettings).
For more information about setting the optimization percent see FromOptimizationPercentage(Int32).
SvgViewbox can be used in xaml. If you would like to read svg file in code and need some more advanced features and options please use ReaderSvg
To read the svg file set Source 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.
<Window x:Class="Ab2d.ReaderSvgSample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ab2d="clr-namespace:Ab2d.Controls;assembly=Ab2d.ReaderSvg" Title="Window1" Height="500" Width="500"/> <Grid> <ab2d:SvgDrawing Name="mySvgDrawing" Source="myClipart.svg" OptimizationPercent="100" Stretch="Uniform"/> </Grid> </Window>
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.SvgDrawing(); mySvgImage.SourceStream = streamResourceInfo.Stream; mySvgImage.Width = 200; mySvgImage.Height = 100; myStackPanel.Controls.Add(mySvgImage); }