summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs23
-rw-r--r--Xamarin.Forms.Xaml/XamlServiceProvider.cs5
-rw-r--r--docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml6
3 files changed, 24 insertions, 10 deletions
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
index a7f59be8..dc80ade2 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -12,21 +12,19 @@ namespace Xamarin.Forms.Xaml
{
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
- if (Key == null)
- {
- var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ if (Key == null) {
+ var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo);
}
- var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues;
+ var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
if (valueProvider == null)
throw new ArgumentException();
- var xmlLineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null;
object resource = null;
- foreach (var p in valueProvider.ParentObjects)
- {
+ foreach (var p in valueProvider.ParentObjects) {
var ve = p as VisualElement;
var resDict = ve?.Resources ?? p as ResourceDictionary;
if (resDict == null)
@@ -36,7 +34,7 @@ namespace Xamarin.Forms.Xaml
}
if (resource == null && Application.Current != null && Application.Current.Resources != null &&
Application.Current.Resources.ContainsKey(Key))
- resource = Application.Current.Resources [Key];
+ resource = Application.Current.Resources[Key];
if (resource == null)
throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
@@ -44,12 +42,17 @@ namespace Xamarin.Forms.Xaml
var bp = valueProvider.TargetProperty as BindableProperty;
var pi = valueProvider.TargetProperty as PropertyInfo;
var propertyType = bp?.ReturnType ?? pi?.PropertyType;
- if (propertyType == null)
+ if (propertyType == null) {
+ if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) {
+ // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty
+ var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() });
+ resource = method.Invoke(resource, new[] { resource });
+ }
return resource;
+ }
if (propertyType.IsAssignableFrom(resource.GetType()))
return resource;
var implicit_op = resource.GetType().GetRuntimeMethod("op_Implicit", new [] { resource.GetType() });
- //This will invoke the op_implicit on OnPlatform<>
if (implicit_op != null && propertyType.IsAssignableFrom(implicit_op.ReturnType))
return implicit_op.Invoke(resource, new [] { resource });
diff --git a/Xamarin.Forms.Xaml/XamlServiceProvider.cs b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
index 19dd96f5..5052a180 100644
--- a/Xamarin.Forms.Xaml/XamlServiceProvider.cs
+++ b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
@@ -137,6 +137,11 @@ namespace Xamarin.Forms.Xaml.Internals
readonly object[] objectAndParents;
readonly object targetProperty;
+ [Obsolete("TargetProperty is now supported, use it")]
+ public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null)
+ {
+ }
+
public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty)
{
if (objectAndParents == null)
diff --git a/docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml b/docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml
index 29e0060a..868fdab1 100644
--- a/docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml
+++ b/docs/Xamarin.Forms.Xaml/Xamarin.Forms.Xaml.Internals/SimpleValueTargetProvider.xml
@@ -21,7 +21,13 @@
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
+ <Attributes>
+ <Attribute>
+ <AttributeName>System.Obsolete("TargetProperty is now supported, use it")</AttributeName>
+ </Attribute>
+ </Attributes>
<Parameters>
<Parameter Name="objectAndParents" Type="System.Object[]" />
</Parameters>