Last active
October 3, 2019 17:18
-
-
Save Adam--/6849f41906b5d847d9a18c1cffbcb08e to your computer and use it in GitHub Desktop.
Load image resource from netstandard library in Xamarin Forms (from https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/ThemingDemo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netstandard2.0</TargetFramework> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | |
<DebugType>pdbonly</DebugType> | |
<DebugSymbols>true</DebugSymbols> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Folder Include="Images\" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Remove="Images\ExampleImage.png" /> | |
</ItemGroup> | |
<ItemGroup> | |
<EmbeddedResource Include="Images\ExampleImage.png" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Xaml; | |
namespace Example | |
{ | |
[ContentProperty("Source")] | |
public class ImageResourceExtension : IMarkupExtension | |
{ | |
public string Source { get; set; } | |
public object ProvideValue(IServiceProvider serviceProvider) | |
{ | |
if (Source == null) | |
return null; | |
return ImageSource.FromResource(Source); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:local="clr-namespace:Example" | |
... | |
... | |
<Image Source="{local:ImageResource ThemingDemo.Images.ExampleImage}" Aspect="AspectFill" /> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment