diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-12-23 08:50:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-23 08:50:19 +0100 |
commit | b96df000db76ba3490589c37e93224271249bc88 (patch) | |
tree | 6389cd652ebe395b51829ee2ec1d41d285ed2fab | |
parent | 2c91b0facd2a25d0de9a283b44cf818329d4c06f (diff) | |
download | xamarin-forms-b96df000db76ba3490589c37e93224271249bc88.tar.gz xamarin-forms-b96df000db76ba3490589c37e93224271249bc88.tar.bz2 xamarin-forms-b96df000db76ba3490589c37e93224271249bc88.zip |
[Xaml] support short Properties for PropertyCondition (#645)
8 files changed, 49 insertions, 15 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs index c1d11487..c78e5184 100644 --- a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs +++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs @@ -30,7 +30,8 @@ namespace Xamarin.Forms.Core.XamlC var parts = value.Split('.'); if (parts.Length == 1) { var parent = node.Parent?.Parent as IElementNode; - if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == "http://xamarin.com/schemas/2014/forms" && (node.Parent as ElementNode)?.XmlType.Name == "Setter") { + if ((node.Parent as ElementNode)?.XmlType.NamespaceUri == "http://xamarin.com/schemas/2014/forms" && + ((node.Parent as ElementNode)?.XmlType.Name == "Setter" || (node.Parent as ElementNode)?.XmlType.Name == "PropertyCondition")) { if (parent.XmlType.NamespaceUri == "http://xamarin.com/schemas/2014/forms" && (parent.XmlType.Name == "Trigger" || parent.XmlType.Name == "DataTrigger" || parent.XmlType.Name == "MultiTrigger" || parent.XmlType.Name == "Style")) { var ttnode = (parent as ElementNode).Properties [new XmlName("", "TargetType")]; @@ -48,6 +49,9 @@ namespace Xamarin.Forms.Core.XamlC } else throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(BindableProperty)}", node); + if (typeName == null || propertyName == null) + throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(BindableProperty)}", node); + var typeRef = GetTypeReference(typeName, module, node); if (typeRef == null) throw new XamlParseException($"Can't resolve {typeName}", node); diff --git a/Xamarin.Forms.Core/BindablePropertyConverter.cs b/Xamarin.Forms.Core/BindablePropertyConverter.cs index a7398e08..08201b01 100644 --- a/Xamarin.Forms.Core/BindablePropertyConverter.cs +++ b/Xamarin.Forms.Core/BindablePropertyConverter.cs @@ -50,6 +50,8 @@ namespace Xamarin.Forms } else if (parentValuesProvider.TargetObject is Trigger) type = (parentValuesProvider.TargetObject as Trigger).TargetType; + else if (parentValuesProvider.TargetObject is PropertyCondition && (parent as TriggerBase) != null) + type = (parent as TriggerBase).TargetType; if (type == null) throw new XamlParseException($"Can't resolve {parts [0]}", lineinfo); diff --git a/Xamarin.Forms.Core/IValueConverterProvider.cs b/Xamarin.Forms.Core/IValueConverterProvider.cs index 1221ce74..b8c684c6 100644 --- a/Xamarin.Forms.Core/IValueConverterProvider.cs +++ b/Xamarin.Forms.Core/IValueConverterProvider.cs @@ -3,7 +3,7 @@ using System.Reflection; namespace Xamarin.Forms.Xaml { - internal interface IValueConverterProvider + interface IValueConverterProvider { object Convert(object value, Type toType, Func<MemberInfo> minfoRetriever, IServiceProvider serviceProvider); } diff --git a/Xamarin.Forms.Core/Interactivity/BindingCondition.cs b/Xamarin.Forms.Core/Interactivity/BindingCondition.cs index 88b7cf36..1d111850 100644 --- a/Xamarin.Forms.Core/Interactivity/BindingCondition.cs +++ b/Xamarin.Forms.Core/Interactivity/BindingCondition.cs @@ -12,7 +12,7 @@ namespace Xamarin.Forms public BindingCondition() { - _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(DataTrigger), null, propertyChanged: OnBoundPropertyChanged); + _boundProperty = BindableProperty.CreateAttached("Bound", typeof(object), typeof(BindingCondition), null, propertyChanged: OnBoundPropertyChanged); } public BindingBase Binding @@ -23,7 +23,7 @@ namespace Xamarin.Forms if (_binding == value) return; if (IsSealed) - throw new InvalidOperationException("Can not change Binding once the Trigger has been applied."); + throw new InvalidOperationException("Can not change Binding once the Condition has been applied."); _binding = value; } } @@ -36,7 +36,7 @@ namespace Xamarin.Forms if (_triggerValue == value) return; if (IsSealed) - throw new InvalidOperationException("Can not change Value once the Trigger has been applied."); + throw new InvalidOperationException("Can not change Value once the Condition has been applied."); _triggerValue = value; } } diff --git a/Xamarin.Forms.Core/Interactivity/MultiCondition.cs b/Xamarin.Forms.Core/Interactivity/MultiCondition.cs index 23ca41c5..1a80190a 100644 --- a/Xamarin.Forms.Core/Interactivity/MultiCondition.cs +++ b/Xamarin.Forms.Core/Interactivity/MultiCondition.cs @@ -8,7 +8,7 @@ namespace Xamarin.Forms public MultiCondition() { - _aggregatedStateProperty = BindableProperty.CreateAttached("AggregatedState", typeof(bool), typeof(DataTrigger), false, propertyChanged: OnAggregatedStatePropertyChanged); + _aggregatedStateProperty = BindableProperty.CreateAttached("AggregatedState", typeof(bool), typeof(MultiCondition), false, propertyChanged: OnAggregatedStatePropertyChanged); Conditions = new TriggerBase.SealedList<Condition>(); } diff --git a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml index 8d78ba93..a8291e38 100644 --- a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml @@ -1,12 +1,24 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.TriggerTests"> <ContentPage.Content> - <Entry x:Name="entry"> - <Entry.Triggers> - <Trigger Property="IsPassword" Value="true" TargetType="Entry"> - <Setter Property="Scale" Value="1.2" /> - </Trigger> - </Entry.Triggers> - </Entry> + <StackLayout> + <Entry x:Name="entry"> + <Entry.Triggers> + <Trigger Property="IsPassword" Value="true" TargetType="Entry"> + <Setter Property="Scale" Value="1.2" /> + </Trigger> + </Entry.Triggers> + </Entry> + <Entry x:Name="entry1"> + <Entry.Triggers> + <MultiTrigger TargetType="Entry"> + <MultiTrigger.Conditions> + <PropertyCondition Value="True" Property="IsPassword" /> + </MultiTrigger.Conditions> + <Setter Property="Scale" Value="1.2" /> + </MultiTrigger> + </Entry.Triggers> + </Entry> + </StackLayout> </ContentPage.Content> </ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs index 79886f8f..5b6755f5 100644 --- a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs @@ -47,6 +47,22 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.AreEqual (Entry.IsPasswordProperty, pwTrigger.Property); Assert.AreEqual (true, pwTrigger.Value); } + + [TestCase(false)] + [TestCase(true)] + public void ValueIsConvertedWithPropertyCondition(bool useCompiledXaml) + { + var layout = new TriggerTests(useCompiledXaml); + Entry entry = layout.entry1; + Assert.NotNull(entry); + + var triggers = entry.Triggers; + Assert.IsNotEmpty(triggers); + var pwTrigger = triggers[0] as MultiTrigger; + var pwCondition = pwTrigger.Conditions[0] as PropertyCondition; + Assert.AreEqual(Entry.IsPasswordProperty, pwCondition.Property); + Assert.AreEqual(true, pwCondition.Value); + } } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml/ValueConverterProvider.cs b/Xamarin.Forms.Xaml/ValueConverterProvider.cs index f7859e0c..6758f9af 100644 --- a/Xamarin.Forms.Xaml/ValueConverterProvider.cs +++ b/Xamarin.Forms.Xaml/ValueConverterProvider.cs @@ -3,7 +3,7 @@ using System.Reflection; namespace Xamarin.Forms.Xaml { - internal class ValueConverterProvider : IValueConverterProvider + class ValueConverterProvider : IValueConverterProvider { public object Convert(object value, Type toType, Func<MemberInfo> minfoRetriever, IServiceProvider serviceProvider) { |