【发布时间】:2017-10-25 15:48:36
【问题描述】:
我在 App.xaml 的 ResourceDictionary 中有一个字符串。
<x:String x:Key="logoEvo">.Images.logoEvo.png</x:String>
我怎样才能像这样在另一个 StaticResource 中使用它:
<Image Source="{sgat:ImageResource SgatMobileOnline{StaticResource logoEvo} }" />
ImageResource 的文件是:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
namespace SgatMobileOnline {
// You exclude the 'Extension' suffix when using in Xaml markup
[Preserve(AllMembers = true)]
[ContentProperty("Source")]
public class ImageResourceExtension : IMarkupExtension {
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider) {
if (Source == null) {
return null;
}
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}
}
谢谢!
【问题讨论】:
标签: c# xaml xamarin xamarin.ios staticresource