diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-03-31 10:38:45 -0700 |
---|---|---|
committer | Samantha Houts <samantha@teamredwall.com> | 2016-03-31 10:38:45 -0700 |
commit | 850591679f51ed27cf00707296156ab4ed363873 (patch) | |
tree | aee758221f272f6e09b5ac55b5c2dec63bd0db97 | |
parent | b3a64fadb3951d4e5e65b5f000a5f930772c01ed (diff) | |
parent | 99b27e9658425da98c6216cc1f804c42d3f43d6f (diff) | |
download | xamarin-forms-850591679f51ed27cf00707296156ab4ed363873.tar.gz xamarin-forms-850591679f51ed27cf00707296156ab4ed363873.tar.bz2 xamarin-forms-850591679f51ed27cf00707296156ab4ed363873.zip |
Merge pull request #32 from xamarin/fix-bugzilla39378
[Controls,Core]Allow well known type conversions on the binding system
4 files changed, 126 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml new file mode 100644 index 00000000..e4d0d904 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml @@ -0,0 +1,12 @@ +<?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" x:Class="Xamarin.Forms.Controls.Issues.Bugzilla39378" xmlns:local="clr-namespace:Xamarin.Forms.Controls"> + <local:TestContentPage.Content> + <Grid BackgroundColor="{Binding BackgroundColor}" Margin="20" Padding="20"> + <Image AutomationId="image1"> + <Image.Source> + <UriImageSource Uri="{Binding HomeImage}" /> + </Image.Source> + </Image> + </Grid> + </local:TestContentPage.Content> +</local:TestContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml.cs new file mode 100644 index 00000000..29b31616 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla39378.xaml.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +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, 39378, "Image binding with caching not operating as expected", PlatformAffected.All)] + public partial class Bugzilla39378 : TestContentPage + { +#if APP + public Bugzilla39378() + { + InitializeComponent(); + } +#endif + + protected override void Init() + { + BindingContext = new ImageController(); + } + + class ImageController : ViewModelBase + { + + public ImageController() + { + HomeImage = "http://xamarin.com/content/images/pages/forms/example-app.png"; + LocalBackgroundImage = "Default-568h@2x.png"; + BackgroundColor = "#00FF00"; + } + + public string BackgroundColor + { + get + { + return _backgroundColor; + } + + set + { + _backgroundColor = value; + OnPropertyChanged(); + } + } + + public string HomeImage + { + get + { + return _homeImage; + } + + set + { + _homeImage = value; + OnPropertyChanged(); + } + } + + public string LocalBackgroundImage + { + get + { + return _localBackgroundImage; + } + + set + { + _localBackgroundImage = value; + OnPropertyChanged(); + } + } + + + string _backgroundColor; + string _homeImage; + string _localBackgroundImage; + } + +#if UITEST + [Test] + public void ImageIsPresent() + { + RunningApp.WaitForElement(q => q.Marked("image1")); + Assert.Inconclusive("Please verify image is present"); + } +#endif + } +} 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 0a2d251b..b22ed58b 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 @@ -375,6 +375,9 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla27350.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28709.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla33578.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39378.xaml.cs"> + <DependentUpon>Bugzilla39378.xaml</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml"> @@ -484,5 +487,8 @@ <SubType>Designer</SubType> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> + <EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla39378.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Xamarin.Forms.Core/BindableProperty.cs b/Xamarin.Forms.Core/BindableProperty.cs index f95d38ab..5eb330ff 100644 --- a/Xamarin.Forms.Core/BindableProperty.cs +++ b/Xamarin.Forms.Core/BindableProperty.cs @@ -30,6 +30,12 @@ namespace Xamarin.Forms public delegate bool ValidateValueDelegate<in TPropertyType>(BindableObject bindable, TPropertyType value); + static readonly Dictionary<Type, TypeConverter> WellKnownConvertTypes = new Dictionary<Type,TypeConverter> + { + { typeof(Uri), new UriTypeConverter() }, + { typeof(Color), new ColorTypeConverter() }, + }; + // more or less the encoding of this, without the need to reflect // http://msdn.microsoft.com/en-us/library/y5b434w4.aspx static readonly Dictionary<Type, Type[]> SimpleConvertTypes = new Dictionary<Type, Type[]> @@ -303,10 +309,15 @@ namespace Xamarin.Forms // Dont support arbitrary IConvertible by limiting which types can use this Type[] convertableTo; + TypeConverter typeConverterTo; if (SimpleConvertTypes.TryGetValue(valueType, out convertableTo) && Array.IndexOf(convertableTo, type) != -1) { value = Convert.ChangeType(value, type); } + else if (WellKnownConvertTypes.TryGetValue(type, out typeConverterTo) && typeConverterTo.CanConvertFrom(valueType)) + { + value = typeConverterTo.ConvertFromInvariantString(value.ToString()); + } else if (!ReturnTypeInfo.IsAssignableFrom(valueType.GetTypeInfo())) { // Is there an implicit cast operator ? |