Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muak/SvgImageSource
Custom ImageSource that will become able to show svg image for Xamarin.Forms
https://github.com/muak/SvgImageSource
Last synced: 29 days ago
JSON representation
Custom ImageSource that will become able to show svg image for Xamarin.Forms
- Host: GitHub
- URL: https://github.com/muak/SvgImageSource
- Owner: muak
- License: mit
- Created: 2017-08-25T08:40:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-12T00:09:38.000Z (over 2 years ago)
- Last Synced: 2024-10-02T18:10:44.875Z (2 months ago)
- Language: C#
- Size: 3.05 MB
- Stars: 62
- Watchers: 5
- Forks: 11
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-xamarin-forms - SvgImageSource ★61
README
# SvgImageSource for Xamarin.Forms
This is a package to add SvgImageSource to Xamarin.Forms as new ImageSource. Thereby Xamarin.Forms.Image will become able to display a SVG image without particular modified.
**Now version is pre release.**
Using this library have to install more than or equal Xamarin.Forms 2.4.0.266 -pre1.## Nuget Installation
https://www.nuget.org/packages/Xamarin.Forms.Svg/
```bash
Install-Package Xamain.Forms.Svg -pre
```You need to install this nuget package to PCL project and each platform project.
## Preparing to use
### iOS AppDelegate.cs.
```csharp
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();Xamarin.Forms.Svg.iOS.SvgImage.Init(); //need to write here
LoadApplication(new App(new iOSInitializer()));
return base.FinishedLaunching(app, options);
}
```### Android MainActivity.cs
```csharp
protected override void OnCreate(Bundle bundle)
{
...
global::Xamarin.Forms.Forms.Init(this, bundle);Xamarin.Forms.Svg.Droid.SvgImage.Init(); //need to write here
LoadApplication(new App(new AndroidInitializer()));
}
```### PCL
In case specifying svg's resource with only Xaml, following code has to be written in App.xaml.cs.
```csharp
public App()
{
InitializeComponent();SvgImageSource.RegisterAssembly();
//SvgImageSource.RegisterAssembly(typeof(typehavingresource)); in case other assembly
}
```## How to use
```csharp
public ImageSource Image { get; set; }public SomeViewModel(){
//specify resource's path
Image = SvgImageSource.FromSvg("Resource.some.svg");
//specify color
Image = SvgImageSource.FromSvg("Resource.some.svg", Color.Red);
//specify width height
Image = SvgImageSource.FromSvg("Resourece.some.svg", 150, 50)
}
``````xml
```
Resource path is found by backward match.### only Xaml
```xml
```
## License
MIT Licensed.