summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-04-12 11:35:01 -0700
committerJason Smith <jason.smith@xamarin.com>2016-04-12 11:35:00 -0700
commit73defe491f11fc417a22eebcf805ee20df90045a (patch)
tree82d5587119d509c45837fd651381d24d824e39fd /Xamarin.Forms.Controls.Issues
parent76c8c57fb30621272e19d493787836ed8c322b9d (diff)
downloadxamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.tar.gz
xamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.tar.bz2
xamarin-forms-73defe491f11fc417a22eebcf805ee20df90045a.zip
[Core] Can bind properties in BindableObjects added to static resources in XAML (#58)
Resources that are `BindableObject`s will inherit the `Parent`'s `BindingContext` unless they are `Element`s that have non-null `Parent`s.
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml21
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml.cs111
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems9
3 files changed, 141 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml
new file mode 100644
index 00000000..d207cd23
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<local:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:test="clr-namespace:Xamarin.Forms.Controls.Issues"
+ xmlns:local="clr-namespace:Xamarin.Forms.Controls"
+ x:Class="Xamarin.Forms.Controls.Issues.Bugzilla23942">
+
+ <local:TestContentPage.Resources>
+ <ResourceDictionary>
+ <test:Bugzilla23942Options x:Key="opts"
+ Text="{Binding DoesItWork}" />
+ </ResourceDictionary>
+ </local:TestContentPage.Resources>
+
+ <local:TestContentPage.Content>
+ <StackLayout>
+ <test:Bugzilla23942Label x:Name="label" Options="{DynamicResource opts}" />
+ </StackLayout>
+ </local:TestContentPage.Content>
+
+</local:TestContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml.cs
new file mode 100644
index 00000000..efa78941
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla23942.xaml.cs
@@ -0,0 +1,111 @@
+using Xamarin.Forms;
+using Xamarin.Forms.CustomAttributes;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 23942, "Cannot bind properties in BindableObjects added to static resources in XAML", PlatformAffected.All)]
+ public partial class Bugzilla23942 : TestContentPage
+ {
+ [Preserve(AllMembers = true)]
+ public class TestViewModel : ViewModelBase
+ {
+ string _doesItWork;
+ public string DoesItWork
+ {
+ get
+ {
+ return _doesItWork;
+ }
+ set
+ {
+ _doesItWork = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
+#if APP
+ public Bugzilla23942()
+ {
+ InitializeComponent();
+ }
+#endif
+
+ private void InitializeView()
+ {
+ TestViewModel vm = new TestViewModel() { DoesItWork = "initial binding works" };
+ BindingContext = vm;
+ vm.DoesItWork = "success";
+ }
+
+ protected override void Init()
+ {
+ InitializeView();
+ }
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+ var lbl = this.FindByName<Bugzilla23942Label>("label");
+ lbl.Text = lbl.Options.Text;
+ }
+
+#if UITEST
+ [Test]
+ public void Bugzilla23942Test()
+ {
+ RunningApp.WaitForElement(q => q.Marked("success"));
+ }
+#endif
+ }
+
+ [Preserve(AllMembers = true)]
+ public class Bugzilla23942Options : BindableObject
+ {
+ public static readonly BindableProperty TextProperty =
+ BindableProperty.Create(propertyName: nameof(Text),
+ returnType: typeof(string),
+ declaringType: typeof(Bugzilla23942Options),
+ defaultValue: default(string));
+
+ public string Text
+ {
+ get
+ {
+ return (string)GetValue(TextProperty);
+ }
+ set
+ {
+ SetValue(TextProperty, value);
+ }
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class Bugzilla23942Label : Label
+ {
+ public static readonly BindableProperty OptionsProperty =
+ BindableProperty.Create(propertyName: nameof(Options),
+ returnType: typeof(Bugzilla23942Options),
+ declaringType: typeof(Bugzilla23942Label),
+ defaultValue: default(Bugzilla23942Options));
+
+ public Bugzilla23942Options Options
+ {
+ get
+ {
+ return (Bugzilla23942Options)GetValue(OptionsProperty);
+ }
+ set
+ {
+ SetValue(OptionsProperty, value);
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index ca43a273..6a1e0b93 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -18,6 +18,9 @@
<DependentUpon>Bugzilla22229.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla22401.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla23942.xaml.cs">
+ <DependentUpon>Bugzilla23942.xaml</DependentUpon>
+ </Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla24769.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla25234.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla25662.cs" />
@@ -516,6 +519,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla23942.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla39636.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>