{
base.Setup ();
Device.PlatformServices = new MockPlatformServices ();
+ Application.Current = new MockApplication();
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ Application.Current = null;
}
[Test]
label.SetDynamicResource (Label.TextProperty, "foo");
label.Resources = new ResourceDictionary { {"foo","FOO"}};
- Assert.AreEqual ("FOO", label.Text);
+ Assume.That(label.Text, Is.EqualTo("FOO"));
label.Resources ["foo"] = "BAR";
Assert.AreEqual ("BAR", label.Text);
}
+
+ [Test]
+ public void FallbackToApplicationCurrent()
+ {
+ Application.Current.Resources = new ResourceDictionary { { "foo", "FOO" } };
+
+ var label = new Label();
+ label.BindingContext = new MockViewModel();
+ label.SetBinding(Label.TextProperty, "Text", BindingMode.TwoWay);
+ label.SetDynamicResource(Label.TextProperty, "foo");
+
+ Assert.That(label.Text, Is.EqualTo("FOO"));
+ }
}
}
\ No newline at end of file
void RegisterImplicitStyles()
{
Type type = TargetType;
- while (true)
- {
+ while (true) {
BindableProperty implicitStyleProperty = BindableProperty.Create("ImplicitStyle", typeof(Style), typeof(VisualElement), default(Style),
- propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable)._mergedStyle.OnImplicitStyleChanged());
- Target.SetDynamicResource(implicitStyleProperty, type.FullName);
+ propertyChanged: (bindable, oldvalue, newvalue) => OnImplicitStyleChanged());
_implicitStyles.Add(implicitStyleProperty);
+ Target.SetDynamicResource(implicitStyleProperty, type.FullName);
type = type.GetTypeInfo().BaseType;
if (s_stopAtTypes.Contains(type))
return;
return true;
element = element.Parent;
}
+
+ //Fallback for the XF previewer
+ if (Application.Current != null && Application.Current.Resources != null && Application.Current.Resources.TryGetValue(key, out value))
+ return true;
+
value = null;
return false;
}