-
Notifications
You must be signed in to change notification settings - Fork 37
FreakySvgImageView
The FreakySvgImageView
class is a versatile SVG image view control designed for use in .NET MAUI applications. It allows you to display Scalable Vector Graphics (SVG) images with various customization options.
-
Type:
Color
-
Default Value:
Colors.Transparent
- Description: Gets or sets the color applied to the SVG image. The SVG image is tinted with this color.
-
Type:
Assembly
-
Default Value:
null
-
Description: Gets or sets the assembly containing the SVG image resource when using
ResourceId
.
-
Type:
ICommand
- Description: Gets or sets the command to be executed when the image is tapped.
-
Type:
object
- Description: Gets or sets the parameter to be passed to the command when the image is tapped.
-
Type:
Aspect
-
Default Value:
Aspect.AspectFit
-
Description: Gets or sets the scaling mode of the SVG image within the view. It supports values like
Aspect.Fill
,Aspect.AspectFit
, andAspect.AspectFill
.
-
Type:
string
-
Default Value:
null
- Description: Gets or sets the resource ID of the SVG image when loaded from the application's resources.
-
Type:
string
-
Default Value:
null
- Description: Gets or sets the Base64-encoded SVG image data to be displayed.
-
Type:
Uri
-
Default Value:
null
- Description: Gets or sets the URI of the SVG image to be displayed. It supports remote image loading.
- Description: Occurs when the image is tapped or clicked. Handle this event to perform actions when the image is interacted with.
-
Description: Releases any resources used by the
FreakySvgImageView
. Call this method when you are done using the control.
-
Description: Initializes a new instance of the
FreakySvgImageView
class. Sets up gesture recognition for tap events and initializes the underlying SVG object.
-
The
FreakySvgImageView
allows you to display SVG images with customizable color, scaling, and interaction capabilities. -
You can load SVG images from different sources, including resources, Base64-encoded strings, and remote URIs.
-
Use the
ImageColor
property to apply a color filter to the SVG image, tinting it with the specified color. -
The
Command
property allows you to define a command that is executed when the image is tapped. You can also provide aCommandParameter
for additional context. -
The
SvgMode
property controls how the SVG image is scaled and fitted within the view, supporting various scaling modes. -
The
Tapped
event enables you to handle interactions with the image, such as tapping or clicking. -
Ensure to call the
Dispose
method when you are done using theFreakySvgImageView
to release any allocated resources.
// Create a FreakySvgImageView instance
var svgImageView = new FreakySvgImageView
{
ResourceId = "YourAppNamespace.Images.myimage.svg",
ImageColor = Color.Blue,
SvgMode = Aspect.AspectFill,
Command = new Command(() => HandleImageTap()),
CommandParameter = "ImageTapped"
};
<freakyControls:FreakySvgImageView
Base64String="{Binding Base64Data}"
Command="{Binding OnTapCommand}"
CommandParameter="{Binding OnTapCommandParam}"
ImageColor="AliceBlue"
Tapped="FreakySvgImageView_Tapped"
SvgAssembly="{x:Static samples:Constants.SvgAssembly}"
SvgMode="AspectFit"
ResourceId="{x:Static samples:Constants.DotnetBot}"/>
Example of a constant class that provides Assembly and ResourceId to the ImageView:
public static class Constants
{
public static readonly Assembly SvgAssembly = typeof(Constants).Assembly;
public static readonly string ResourcePath = "Samples.Resources.Images.";
public static readonly string DotnetBot = ResourcePath+ "dotnet_bot.svg";
}
Still confused? Don't Worry just check the Sample project for how to configure this :)