diff --git a/Behaviors.sln b/Behaviors.sln old mode 100755 new mode 100644 index c79bf4f..9c3d484 --- a/Behaviors.sln +++ b/Behaviors.sln @@ -1,20 +1,18 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2036 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors", "Library\Behaviors\Behaviors.csproj", "{98DC638E-301A-4F8E-AF88-5C0C240D24DC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Behaviors", "Library\Behaviors\Behaviors.csproj", "{98DC638E-301A-4F8E-AF88-5C0C240D24DC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample", "Sample\Behaviors.Sample\Behaviors.Sample.csproj", "{63211B14-3CEB-4F12-B447-129BD647AADA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Behaviors.Sample", "Sample\Behaviors.Sample\Behaviors.Sample.csproj", "{63211B14-3CEB-4F12-B447-129BD647AADA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample.iOS", "Sample\iOS\Behaviors.Sample.iOS.csproj", "{058290EB-974F-4ABF-849B-D61EBEB388D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample.Droid", "Sample\Droid\Behaviors.Sample.Droid.csproj", "{06D10497-AB57-4353-8D65-2EFF5AE04FB2}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample.WinPhone81", "Sample\WinPhone81\Behaviors.Sample.WinPhone81.csproj", "{54381DD6-292C-42FC-AFC1-57221B60DE02}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample.UWP", "Sample\UWP\Behaviors.Sample.UWP.csproj", "{4D760038-F76B-40FF-88D9-55A06E802342}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Behaviors.Sample.Droid", "Sample\Droid\Behaviors.Sample.Droid.csproj", "{06D10497-AB57-4353-8D65-2EFF5AE04FB2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +43,7 @@ Global {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Debug|x64.ActiveCfg = Debug|Any CPU {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Debug|x64.Build.0 = Debug|Any CPU {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Debug|x86.ActiveCfg = Debug|Any CPU + {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Debug|x86.Build.0 = Debug|Any CPU {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Release|Any CPU.ActiveCfg = Release|Any CPU {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Release|Any CPU.Build.0 = Release|Any CPU {98DC638E-301A-4F8E-AF88-5C0C240D24DC}.Release|ARM.ActiveCfg = Release|Any CPU @@ -69,6 +68,7 @@ Global {63211B14-3CEB-4F12-B447-129BD647AADA}.Debug|x64.ActiveCfg = Debug|Any CPU {63211B14-3CEB-4F12-B447-129BD647AADA}.Debug|x64.Build.0 = Debug|Any CPU {63211B14-3CEB-4F12-B447-129BD647AADA}.Debug|x86.ActiveCfg = Debug|Any CPU + {63211B14-3CEB-4F12-B447-129BD647AADA}.Debug|x86.Build.0 = Debug|Any CPU {63211B14-3CEB-4F12-B447-129BD647AADA}.Release|Any CPU.ActiveCfg = Release|Any CPU {63211B14-3CEB-4F12-B447-129BD647AADA}.Release|Any CPU.Build.0 = Release|Any CPU {63211B14-3CEB-4F12-B447-129BD647AADA}.Release|ARM.ActiveCfg = Release|Any CPU @@ -103,68 +103,6 @@ Global {058290EB-974F-4ABF-849B-D61EBEB388D7}.Release|Mixed Platforms.Build.0 = Release|iPhoneSimulator {058290EB-974F-4ABF-849B-D61EBEB388D7}.Release|x64.ActiveCfg = Release|iPhoneSimulator {058290EB-974F-4ABF-849B-D61EBEB388D7}.Release|x86.ActiveCfg = Release|iPhoneSimulator - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|ARM.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhone.Build.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.Build.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.Deploy.0 = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x86.ActiveCfg = Debug|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Any CPU.Build.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|ARM.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhone.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhone.Build.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.ActiveCfg = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.Build.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.Deploy.0 = Release|Any CPU - {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x86.ActiveCfg = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Any CPU.Build.0 = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|ARM.ActiveCfg = Debug|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|ARM.Build.0 = Debug|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|ARM.Deploy.0 = Debug|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|Mixed Platforms.Deploy.0 = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x64.ActiveCfg = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x64.Build.0 = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x64.Deploy.0 = Debug|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x86.ActiveCfg = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x86.Build.0 = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Debug|x86.Deploy.0 = Debug|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Any CPU.ActiveCfg = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Any CPU.Build.0 = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Any CPU.Deploy.0 = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|ARM.ActiveCfg = Release|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|ARM.Build.0 = Release|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|ARM.Deploy.0 = Release|ARM - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|iPhone.ActiveCfg = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Mixed Platforms.Build.0 = Release|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|Mixed Platforms.Deploy.0 = Release|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x64.ActiveCfg = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x64.Build.0 = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x64.Deploy.0 = Release|Any CPU - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x86.ActiveCfg = Release|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x86.Build.0 = Release|x86 - {54381DD6-292C-42FC-AFC1-57221B60DE02}.Release|x86.Deploy.0 = Release|x86 {4D760038-F76B-40FF-88D9-55A06E802342}.Debug|Any CPU.ActiveCfg = Debug|x86 {4D760038-F76B-40FF-88D9-55A06E802342}.Debug|ARM.ActiveCfg = Debug|ARM {4D760038-F76B-40FF-88D9-55A06E802342}.Debug|ARM.Build.0 = Debug|ARM @@ -195,8 +133,39 @@ Global {4D760038-F76B-40FF-88D9-55A06E802342}.Release|x86.ActiveCfg = Release|x86 {4D760038-F76B-40FF-88D9-55A06E802342}.Release|x86.Build.0 = Release|x86 {4D760038-F76B-40FF-88D9-55A06E802342}.Release|x86.Deploy.0 = Release|x86 + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|ARM.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhone.Build.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.Build.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x64.Deploy.0 = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Debug|x86.ActiveCfg = Debug|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Any CPU.Build.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|ARM.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhone.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhone.Build.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.ActiveCfg = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.Build.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x64.Deploy.0 = Release|Any CPU + {06D10497-AB57-4353-8D65-2EFF5AE04FB2}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FD479C9F-357D-47BC-A933-57E420F8EBD7} + EndGlobalSection EndGlobal diff --git a/Library/Behaviors/ActionCollection.cs b/Library/Behaviors/ActionCollection.cs index 760f7e5..b9af3bb 100755 --- a/Library/Behaviors/ActionCollection.cs +++ b/Library/Behaviors/ActionCollection.cs @@ -4,39 +4,39 @@ namespace Behaviors { - [Preserve(AllMembers = true)] - public class ActionCollection : BindableObjectCollection - { - public ActionCollection() - { - CollectionChanged += ActionCollection_CollectionChanged; - } + [Preserve(AllMembers = true)] + public class ActionCollection : BindableObjectCollection + { + public ActionCollection() + { + CollectionChanged += ActionCollection_CollectionChanged; + } - void ActionCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - var collectionChange = e.Action; + void ActionCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + var collectionChange = e.Action; - if (collectionChange == NotifyCollectionChangedAction.Reset) - { - foreach (BindableObject bindable in this) - { - ActionCollection.VerifyType(bindable); - } - } + if (collectionChange == NotifyCollectionChangedAction.Reset) + { + foreach (BindableObject bindable in this) + { + ActionCollection.VerifyType(bindable); + } + } else if (collectionChange == NotifyCollectionChangedAction.Replace) - { - BindableObject changed = this[(int)e.NewStartingIndex]; + { + BindableObject changed = this[(int)e.NewStartingIndex]; ActionCollection.VerifyType(changed); - } - } + } + } - static void VerifyType(BindableObject bindable) - { - if (!(bindable is IAction)) - { - throw new InvalidOperationException("Non-IAction added to IAction collection"); - } - } - } + static void VerifyType(BindableObject bindable) + { + if (!(bindable is IAction)) + { + throw new InvalidOperationException("Non-IAction added to IAction collection"); + } + } + } } diff --git a/Library/Behaviors/AnimationBase.cs b/Library/Behaviors/AnimationBase.cs index bb24152..98d84fa 100755 --- a/Library/Behaviors/AnimationBase.cs +++ b/Library/Behaviors/AnimationBase.cs @@ -5,10 +5,10 @@ namespace Behaviors [Preserve(AllMembers = true)] public class AnimationBase : BindableObject { - public static readonly BindableProperty DurationProperty = BindableProperty.Create("Duration", typeof(int), typeof(AnimationBase), 250); - public static readonly BindableProperty EasingFunctionProperty = BindableProperty.Create("EasingFunction", typeof(EasingFunction), typeof(AnimationBase), EasingFunction.Linear); - public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create("TargetObject", typeof(object), typeof(AnimationBase), null); - public static readonly BindableProperty AwaitProperty = BindableProperty.Create("Await", typeof(bool), typeof(AnimationBase), false); + public static readonly BindableProperty DurationProperty = BindableProperty.Create(nameof(Duration), typeof(int), typeof(AnimationBase), 250); + public static readonly BindableProperty EasingFunctionProperty = BindableProperty.Create(nameof(EasingFunction), typeof(EasingFunction), typeof(AnimationBase), EasingFunction.Linear); + public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create(nameof(TargetObject), typeof(object), typeof(AnimationBase), null); + public static readonly BindableProperty AwaitProperty = BindableProperty.Create(nameof(Await), typeof(bool), typeof(AnimationBase), false); public int Duration { diff --git a/Library/Behaviors/BehaviorPropertiesBase.cs b/Library/Behaviors/BehaviorPropertiesBase.cs new file mode 100644 index 0000000..089042d --- /dev/null +++ b/Library/Behaviors/BehaviorPropertiesBase.cs @@ -0,0 +1,24 @@ +using Xamarin.Forms; + +namespace Behaviors +{ + [Preserve(AllMembers = true)] + [ContentProperty("Actions")] + public class BehaviorPropertiesBase : BehaviorBase + { + public static readonly BindableProperty ActionsProperty = BindableProperty.Create(nameof(Actions), typeof(ActionCollection), typeof(BehaviorPropertiesBase), null); + + public ActionCollection Actions + { + get + { + return (ActionCollection)GetValue(ActionsProperty); + } + } + + public BehaviorPropertiesBase() + { + SetValue(ActionsProperty, new ActionCollection()); + } + } +} diff --git a/Library/Behaviors/Behaviors.csproj b/Library/Behaviors/Behaviors.csproj index 40bf4f7..2662832 100644 --- a/Library/Behaviors/Behaviors.csproj +++ b/Library/Behaviors/Behaviors.csproj @@ -1,99 +1,32 @@ - - - - - Debug - AnyCPU - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {98DC638E-301A-4F8E-AF88-5C0C240D24DC} - Library - Behaviors - Behaviors - v4.5 - Profile259 - 10.0 - - - Behaviors.Forms - 1.2.0 - David Britch - Using behaviors and actions, developers can create a variety of scenarios in XAML that previously required C#. + + + netstandard1.0 + Behaviors.Forms + 1.4.0 + David Britch + Using behaviors and actions, developers can create a variety of scenarios in XAML that previously required C#. Based on, and inspired by the Blend SDK behaviours. - david.britch - https://github.com/davidbritch/behaviors - This release marks preserves each type to stop the linker removing types that aren't statically referenced by the calling application. - Behaviours are attached to a control and listen for something to happen. That something can be an event firing or some data changing. + https://github.com/davidbritch/behaviors/blob/master/LICENSE + david.britch + https://github.com/davidbritch/behaviors + This release is compatible with Xamarin.Forms 3. + Behaviours are attached to a control and listen for something to happen. That something can be an event firing or some data changing. Actions are invoked by Behaviours and execute on a control. - Xamarin Xamarin.Forms EventTriggerBehavior EventHandlerBehavior DataTriggerBehavior DataChangedBehavior InvokeCommandAction InvokeMethodAction SetPropertyAction FadeAction RotateAction ScaleAction TranslateAction - Behaviors for Xamarin.Forms - true - https://github.com/davidbritch/behaviors/blob/master/LICENSE - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + Xamarin Xamarin.Forms EventHandlerBehavior DataChangedBehavior InvokeCommandAction InvokeMethodAction SetPropertyAction FadeAction RotateAction ScaleAction TranslateAction GoToStateAction + Behaviors for Xamarin.Forms + true + + + + + + + - - - + + + + \ No newline at end of file diff --git a/Library/Behaviors/BindableObjectCollection.cs b/Library/Behaviors/BindableObjectCollection.cs index da3b6a6..ef8e695 100755 --- a/Library/Behaviors/BindableObjectCollection.cs +++ b/Library/Behaviors/BindableObjectCollection.cs @@ -6,7 +6,7 @@ namespace Behaviors { [Preserve(AllMembers = true)] - public class BindableObjectCollection : BindableObject, IList, INotifyCollectionChanged + public class BindableObjectCollection : BindableObject, IEnumerable, INotifyCollectionChanged { List Items = new List(); diff --git a/Library/Behaviors/DataChangedBehavior.cs b/Library/Behaviors/DataChangedBehavior.cs index 7d948e3..9d6929c 100755 --- a/Library/Behaviors/DataChangedBehavior.cs +++ b/Library/Behaviors/DataChangedBehavior.cs @@ -5,27 +5,11 @@ namespace Behaviors { [Preserve(AllMembers = true)] - [ContentProperty("Actions")] - public sealed class DataChangedBehavior : BehaviorBase + public sealed class DataChangedBehavior : BehaviorPropertiesBase { - public static readonly BindableProperty ActionsProperty = BindableProperty.Create("Actions", typeof(ActionCollection), typeof(DataChangedBehavior), null); - public static readonly BindableProperty BindingProperty = BindableProperty.Create("Binding", typeof(object), typeof(DataChangedBehavior), null, propertyChanged: OnValueChanged); + public static readonly BindableProperty BindingProperty = BindableProperty.Create(nameof(Binding), typeof(object), typeof(DataChangedBehavior), null, propertyChanged: OnValueChanged); public static readonly BindableProperty ComparisonProperty = BindableProperty.Create("Comparison", typeof(ComparisonCondition), typeof(DataChangedBehavior), ComparisonCondition.Equal, propertyChanged: OnValueChanged); - public static readonly BindableProperty ValueProperty = BindableProperty.Create("Value", typeof(object), typeof(DataChangedBehavior), null, propertyChanged: OnValueChanged); - - public ActionCollection Actions - { - get - { - var actionCollection = (ActionCollection)GetValue(ActionsProperty); - if (actionCollection == null) - { - actionCollection = new ActionCollection(); - SetValue(ActionsProperty, actionCollection); - } - return actionCollection; - } - } + public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(object), typeof(DataChangedBehavior), null, propertyChanged: OnValueChanged); public object Binding { diff --git a/Library/Behaviors/EventHandlerBehavior.cs b/Library/Behaviors/EventHandlerBehavior.cs index d0b328b..7d2236e 100755 --- a/Library/Behaviors/EventHandlerBehavior.cs +++ b/Library/Behaviors/EventHandlerBehavior.cs @@ -5,13 +5,13 @@ namespace Behaviors { [Preserve(AllMembers = true)] - [ContentProperty("Actions")] - public sealed class EventHandlerBehavior : BehaviorBase + public sealed class EventHandlerBehavior : BehaviorPropertiesBase { - Delegate eventHandler; + Delegate _eventHandler; + object _resolvedSource; - public static readonly BindableProperty EventNameProperty = BindableProperty.Create("EventName", typeof(string), typeof(EventHandlerBehavior), null, propertyChanged: OnEventNameChanged); - public static readonly BindableProperty ActionsProperty = BindableProperty.Create("Actions", typeof(ActionCollection), typeof(EventHandlerBehavior), null); + public static readonly BindableProperty EventNameProperty = BindableProperty.Create(nameof(EventName), typeof(string), typeof(EventHandlerBehavior), propertyChanged: OnEventNameChanged); + public static readonly BindableProperty SourceObjectProperty = BindableProperty.Create(nameof(SourceObject), typeof(object), typeof(EventHandlerBehavior), null, propertyChanged: OnSourceObjectChanged); public string EventName { @@ -19,67 +19,87 @@ public string EventName set { SetValue(EventNameProperty, value); } } - public ActionCollection Actions + public object SourceObject { - get - { - var actionCollection = (ActionCollection)GetValue(ActionsProperty); - if (actionCollection == null) - { - actionCollection = new ActionCollection(); - SetValue(ActionsProperty, actionCollection); - } - return actionCollection; - } + get { return GetValue(SourceObjectProperty); } + set { SetValue(SourceObjectProperty, value); } } protected override void OnAttachedTo(VisualElement bindable) { base.OnAttachedTo(bindable); - RegisterEvent(EventName); + SetResolvedSource(ComputeResolvedSource()); } protected override void OnDetachingFrom(VisualElement bindable) { - DeregisterEvent(EventName); base.OnDetachingFrom(bindable); + SetResolvedSource(null); } - void RegisterEvent(string name) + void SetResolvedSource(object newSource) { - if (string.IsNullOrWhiteSpace(name)) + if (AssociatedObject == null || _resolvedSource == newSource) { return; } + if (_resolvedSource != null) + { + DeregisterEvent(EventName); + } + _resolvedSource = newSource; + if (_resolvedSource != null) + { + RegisterEvent(EventName); + } + } + + object ComputeResolvedSource() + { + if (SourceObject != null) + { + return SourceObject; + } + return AssociatedObject; + } - EventInfo eventInfo = AssociatedObject.GetType().GetRuntimeEvent(EventName); + void RegisterEvent(string eventName) + { + if (string.IsNullOrWhiteSpace(eventName)) + { + return; + } + + Type sourceObjectType = _resolvedSource.GetType(); + EventInfo eventInfo = sourceObjectType.GetRuntimeEvent(eventName); if (eventInfo == null) { - throw new ArgumentException(string.Format("EventHandlerBehavior: Can't register the '{0}' event.", EventName)); + return; } MethodInfo methodInfo = typeof(EventHandlerBehavior).GetTypeInfo().GetDeclaredMethod("OnEvent"); - eventHandler = methodInfo.CreateDelegate(eventInfo.EventHandlerType, this); - eventInfo.AddEventHandler(AssociatedObject, eventHandler); + _eventHandler = methodInfo.CreateDelegate(eventInfo.EventHandlerType, this); + eventInfo.AddEventHandler(_resolvedSource, _eventHandler); } - void DeregisterEvent(string name) + void DeregisterEvent(string eventName) { - if (string.IsNullOrWhiteSpace(name)) + if (string.IsNullOrWhiteSpace(eventName)) { return; } - if (eventHandler == null) + if (_eventHandler == null) { return; } - EventInfo eventInfo = AssociatedObject.GetType().GetRuntimeEvent(EventName); + + EventInfo eventInfo = _resolvedSource.GetType().GetRuntimeEvent(eventName); if (eventInfo == null) { throw new ArgumentException(string.Format("EventHandlerBehavior: Can't de-register the '{0}' event.", EventName)); } - eventInfo.RemoveEventHandler(AssociatedObject, eventHandler); - eventHandler = null; + eventInfo.RemoveEventHandler(_resolvedSource, _eventHandler); + _eventHandler = null; } async void OnEvent(object sender, object eventArgs) @@ -95,7 +115,7 @@ async void OnEvent(object sender, object eventArgs) static void OnEventNameChanged(BindableObject bindable, object oldValue, object newValue) { var behavior = (EventHandlerBehavior)bindable; - if (behavior.AssociatedObject == null) + if (behavior.AssociatedObject == null || behavior._resolvedSource == null) { return; } @@ -106,6 +126,12 @@ static void OnEventNameChanged(BindableObject bindable, object oldValue, object behavior.DeregisterEvent(oldEventName); behavior.RegisterEvent(newEventName); } + + static void OnSourceObjectChanged(BindableObject bindable, object oldValue, object newValue) + { + var behavior = (EventHandlerBehavior)bindable; + behavior.SetResolvedSource(behavior.ComputeResolvedSource()); + } } } diff --git a/Library/Behaviors/FadeAction.cs b/Library/Behaviors/FadeAction.cs index 32046e7..b70efe3 100755 --- a/Library/Behaviors/FadeAction.cs +++ b/Library/Behaviors/FadeAction.cs @@ -8,7 +8,7 @@ namespace Behaviors [Preserve(AllMembers = true)] public class FadeAction : AnimationBase, IAction { - public static readonly BindableProperty FinalOpacityProperty = BindableProperty.Create("FinalOpacity", typeof(double), typeof(FadeAction), 1.0); + public static readonly BindableProperty FinalOpacityProperty = BindableProperty.Create(nameof(FinalOpacity), typeof(double), typeof(FadeAction), 1.0); public double FinalOpacity { diff --git a/Library/Behaviors/GoToStateAction.cs b/Library/Behaviors/GoToStateAction.cs new file mode 100644 index 0000000..87a928d --- /dev/null +++ b/Library/Behaviors/GoToStateAction.cs @@ -0,0 +1,61 @@ +using System; +using System.Threading.Tasks; +using Xamarin.Forms; + +#pragma warning disable 1998 + +namespace Behaviors +{ + [Preserve(AllMembers = true)] + public sealed class GoToStateAction : BindableObject, IAction + { + public static readonly BindableProperty StateNameProperty = BindableProperty.Create(nameof(StateNameProperty), typeof(string), typeof(GoToStateAction), null); + public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create(nameof(TargetObject), typeof(VisualElement), typeof(GoToStateAction), null); + + public string StateName + { + get { return (string)GetValue(StateNameProperty); } + set { SetValue(StateNameProperty, value); } + } + + public object TargetObject + { + get { return (VisualElement)GetValue(TargetObjectProperty); } + set { SetValue(TargetObjectProperty, value); } + } + + public async Task Execute(object sender, object parameter) + { + if (string.IsNullOrWhiteSpace(StateName)) + { + return false; + } + + if (TargetObject != null) + { + VisualElement element = TargetObject as VisualElement; + if (element == null) + { + return false; + } + + return GoToState(element, StateName); + } + return false; + } + + bool GoToState(VisualElement visualElement, string stateName) + { + if (visualElement == null) + { + throw new ArgumentNullException(nameof(visualElement)); + } + if (string.IsNullOrWhiteSpace(stateName)) + { + throw new ArgumentNullException(nameof(stateName)); + } + + return VisualStateManager.GoToState(visualElement, stateName); + } + } +} diff --git a/Library/Behaviors/InvokeCommandAction.cs b/Library/Behaviors/InvokeCommandAction.cs index 7a595ed..fdcf16b 100755 --- a/Library/Behaviors/InvokeCommandAction.cs +++ b/Library/Behaviors/InvokeCommandAction.cs @@ -9,10 +9,11 @@ namespace Behaviors [Preserve(AllMembers = true)] public sealed class InvokeCommandAction : BindableObject, IAction { - public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(InvokeCommandAction), null); - public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(InvokeCommandAction), null); - public static readonly BindableProperty InputConverterProperty = BindableProperty.Create("Converter", typeof(IValueConverter), typeof(InvokeCommandAction), null); - + public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(InvokeCommandAction), null); + public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(InvokeCommandAction), null); + public static readonly BindableProperty InputConverterProperty = BindableProperty.Create(nameof(Converter), typeof(IValueConverter), typeof(InvokeCommandAction), null); + public static readonly BindableProperty InputConverterParameterProperty = BindableProperty.Create(nameof(ConverterParameter), typeof(object), typeof(InvokeCommandAction), null); + public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } @@ -31,6 +32,12 @@ public IValueConverter Converter set { SetValue(InputConverterProperty, value); } } + public object ConverterParameter + { + get { return GetValue(InputConverterParameterProperty); } + set { SetValue(InputConverterParameterProperty, value); } + } + public async Task Execute(object sender, object parameter) { if (Command == null) @@ -45,9 +52,10 @@ public async Task Execute(object sender, object parameter) } else if (Converter != null) { - resolvedParameter = Converter.Convert(parameter, typeof(object), null, null); + resolvedParameter = Converter.Convert(parameter, typeof(object), ConverterParameter, null); } - else { + else + { resolvedParameter = parameter; } diff --git a/Library/Behaviors/InvokeMethodAction.cs b/Library/Behaviors/InvokeMethodAction.cs index bb662ec..dde7aa7 100755 --- a/Library/Behaviors/InvokeMethodAction.cs +++ b/Library/Behaviors/InvokeMethodAction.cs @@ -11,12 +11,12 @@ namespace Behaviors [Preserve(AllMembers = true)] public class InvokeMethodAction : BindableObject, IAction { - Type targetObjectType; - MethodDescriptor cachedMethodDescriptor; - List methodDescriptors = new List(); + Type _targetObjectType; + MethodDescriptor _cachedMethodDescriptor; + List _methodDescriptors = new List(); - public static readonly BindableProperty MethodNameProperty = BindableProperty.Create("MethodName", typeof(string), typeof(InvokeMethodAction), null, propertyChanged: OnMethodNameChanged); - public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create("TargetObject", typeof(object), typeof(InvokeMethodAction), null, propertyChanged: OnTargetObjectChanged); + public static readonly BindableProperty MethodNameProperty = BindableProperty.Create(nameof(MethodName), typeof(string), typeof(InvokeMethodAction), null, propertyChanged: OnMethodNameChanged); + public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create(nameof(TargetObject), typeof(object), typeof(InvokeMethodAction), null, propertyChanged: OnTargetObjectChanged); public string MethodName { @@ -79,12 +79,12 @@ MethodDescriptor FindBestMethod(object parameter) if (parameterTypeInfo == null) { - return cachedMethodDescriptor; + return _cachedMethodDescriptor; } MethodDescriptor mostDerivedMethod = null; - foreach (MethodDescriptor currentMethod in methodDescriptors) + foreach (MethodDescriptor currentMethod in _methodDescriptors) { TypeInfo currentTypeInfo = currentMethod.SecondParameterTypeInfo; @@ -97,42 +97,42 @@ MethodDescriptor FindBestMethod(object parameter) } } - return mostDerivedMethod ?? cachedMethodDescriptor; + return mostDerivedMethod ?? _cachedMethodDescriptor; } void UpdateTargetType(Type newTargetType) { - if (newTargetType == targetObjectType) + if (newTargetType == _targetObjectType) { return; } - targetObjectType = newTargetType; + _targetObjectType = newTargetType; UpdateMethodDescriptors(); } void UpdateMethodDescriptors() { - methodDescriptors.Clear(); - cachedMethodDescriptor = null; + _methodDescriptors.Clear(); + _cachedMethodDescriptor = null; - if (string.IsNullOrWhiteSpace(MethodName) || targetObjectType == null) + if (string.IsNullOrWhiteSpace(MethodName) || _targetObjectType == null) { return; } - foreach (MethodInfo method in targetObjectType.GetRuntimeMethods()) + foreach (MethodInfo method in _targetObjectType.GetRuntimeMethods()) { if (string.Equals(method.Name, MethodName, StringComparison.Ordinal) && method.ReturnType == typeof(void) && method.IsPublic) { var parameters = method.GetParameters(); if (parameters.Length == 0) { - cachedMethodDescriptor = new MethodDescriptor(method, parameters); + _cachedMethodDescriptor = new MethodDescriptor(method, parameters); } else if (parameters.Length == 2 && parameters[0].ParameterType == typeof(object)) { - methodDescriptors.Add(new MethodDescriptor(method, parameters)); + _methodDescriptors.Add(new MethodDescriptor(method, parameters)); } } } diff --git a/Library/Behaviors/Properties/AssemblyInfo.cs b/Library/Behaviors/Properties/AssemblyInfo.cs deleted file mode 100755 index ba12e30..0000000 --- a/Library/Behaviors/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Behaviors")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("David Britch")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.2.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/Library/Behaviors/RotateAction.cs b/Library/Behaviors/RotateAction.cs index 9009021..0b0e1aa 100755 --- a/Library/Behaviors/RotateAction.cs +++ b/Library/Behaviors/RotateAction.cs @@ -8,9 +8,9 @@ namespace Behaviors [Preserve(AllMembers = true)] public class RotateAction : AnimationBase, IAction { - public static readonly BindableProperty FinalAngleProperty = BindableProperty.Create("FinalAngle", typeof(double), typeof(RotateAction), 0.0); - public static readonly BindableProperty IsRelativeProperty = BindableProperty.Create("IsRelative", typeof(bool), typeof(RotateAction), false); - public static readonly BindableProperty AxisProperty = BindableProperty.Create("Axis", typeof(RotationAxis), typeof(RotateAction), RotationAxis.Z); + public static readonly BindableProperty FinalAngleProperty = BindableProperty.Create(nameof(FinalAngle), typeof(double), typeof(RotateAction), 0.0); + public static readonly BindableProperty IsRelativeProperty = BindableProperty.Create(nameof(IsRelative), typeof(bool), typeof(RotateAction), false); + public static readonly BindableProperty AxisProperty = BindableProperty.Create(nameof(Axis), typeof(RotationAxis), typeof(RotateAction), RotationAxis.Z); public double FinalAngle { diff --git a/Library/Behaviors/ScaleAction.cs b/Library/Behaviors/ScaleAction.cs index 8540479..456ccf3 100755 --- a/Library/Behaviors/ScaleAction.cs +++ b/Library/Behaviors/ScaleAction.cs @@ -8,8 +8,8 @@ namespace Behaviors [Preserve(AllMembers = true)] public class ScaleAction : AnimationBase, IAction { - public static readonly BindableProperty FinalScaleProperty = BindableProperty.Create("FinalScale", typeof(double), typeof(ScaleAction), 1.0); - public static readonly BindableProperty IsRelativeProperty = BindableProperty.Create("IsRelative", typeof(bool), typeof(ScaleAction), false); + public static readonly BindableProperty FinalScaleProperty = BindableProperty.Create(nameof(FinalScale), typeof(double), typeof(ScaleAction), 1.0); + public static readonly BindableProperty IsRelativeProperty = BindableProperty.Create(nameof(IsRelative), typeof(bool), typeof(ScaleAction), false); public double FinalScale { diff --git a/Library/Behaviors/SetPropertyAction.cs b/Library/Behaviors/SetPropertyAction.cs index a1fe668..9d9fcbc 100755 --- a/Library/Behaviors/SetPropertyAction.cs +++ b/Library/Behaviors/SetPropertyAction.cs @@ -10,9 +10,9 @@ namespace Behaviors [Preserve(AllMembers = true)] public sealed class SetPropertyAction : BindableObject, IAction { - public static readonly BindableProperty PropertyNameProperty = BindableProperty.Create("PropertyName", typeof(string), typeof(SetPropertyAction), null); - public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create("TargetObject", typeof(object), typeof(SetPropertyAction), null); - public static readonly BindableProperty ValueProperty = BindableProperty.Create("Value", typeof(object), typeof(SetPropertyAction), null); + public static readonly BindableProperty PropertyNameProperty = BindableProperty.Create(nameof(PropertyName), typeof(string), typeof(SetPropertyAction), null); + public static readonly BindableProperty TargetObjectProperty = BindableProperty.Create(nameof(TargetObject), typeof(object), typeof(SetPropertyAction), null); + public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(object), typeof(SetPropertyAction), null); public string PropertyName { diff --git a/Library/Behaviors/TranslateAction.cs b/Library/Behaviors/TranslateAction.cs index 6774d2b..604cf4f 100755 --- a/Library/Behaviors/TranslateAction.cs +++ b/Library/Behaviors/TranslateAction.cs @@ -8,8 +8,8 @@ namespace Behaviors [Preserve(AllMembers = true)] public class TranslateAction : AnimationBase, IAction { - public static readonly BindableProperty XProperty = BindableProperty.Create("X", typeof(double), typeof(TranslateAction), 1.0); - public static readonly BindableProperty YProperty = BindableProperty.Create("Y", typeof(double), typeof(TranslateAction), 1.0); + public static readonly BindableProperty XProperty = BindableProperty.Create(nameof(X), typeof(double), typeof(TranslateAction), 1.0); + public static readonly BindableProperty YProperty = BindableProperty.Create(nameof(Y), typeof(double), typeof(TranslateAction), 1.0); public double X { diff --git a/Library/Behaviors/packages.config b/Library/Behaviors/packages.config deleted file mode 100644 index 8c8448c..0000000 --- a/Library/Behaviors/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/README.md b/README.md index bc760a1..a8fd2d9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Behaviors for Xamarin.Forms -Documentation: +- Use v1.4.0 of the [NuGet package](https://www.nuget.org/packages/Behaviors.Forms/1.4.0) for compatibility with Xamarin.Forms 3.0. +- Use v1.3.0 of the [NuGet package](https://www.nuget.org/packages/Behaviors.Forms/1.3.0) for apps that use .NET Standard. +- Use v1.2.0 of the [NuGet package](https://www.nuget.org/packages/Behaviors.Forms/1.2.0) for apps that use PCLs. + +## Documentation - [Behaviours Library for Xamarin.Forms](http://www.davidbritch.com/2016/02/behaviours-library-for-xamarinforms_24.html) - [EventHandlerBehavior and InvokeCommandAction](http://www.davidbritch.com/2016/02/xamarinforms-behaviors.html) @@ -15,4 +19,7 @@ Documentation: - [Xamarin.Forms Behaviors: TranslateAction](http://www.davidbritch.com/2016/06/xamarinforms-behaviors-translateaction.html) - [Xamarin.Forms Behaviors: ScaleAction](http://www.davidbritch.com/2016/06/xamarinforms-behaviors-scaleaction.html) - [Xamarin.Forms Behaviors: RotateAction](http://www.davidbritch.com/2016/07/xamarinforms-behaviors-rotateaction.html) - +- [Behaviors Library 1.4](https://www.davidbritch.com/2018/05/behaviours-library-14.html) +- [Xamarin.Forms Behaviors: GoToStateAction](https://www.davidbritch.com/2018/05/xamarinforms-behaviors-gotostateaction.html) +- [Xamarin.Forms Behaviors: EventHandlerBehavior and the SourceObject](https://www.davidbritch.com/2018/06/xamarinforms-behaviors.html) +- [Xamarin.Forms Behaviors: InvokeCommandAction and ConverterParameter](https://www.davidbritch.com/2018/06/xamarinforms-behaviors_12.html) diff --git a/Sample/Behaviors.Sample/AnimationDemoPage.xaml b/Sample/Behaviors.Sample/AnimationDemoPage.xaml old mode 100755 new mode 100644 index 2cbe192..9919ec7 --- a/Sample/Behaviors.Sample/AnimationDemoPage.xaml +++ b/Sample/Behaviors.Sample/AnimationDemoPage.xaml @@ -1,16 +1,17 @@ - + - + - diff --git a/Sample/Behaviors.Sample/App.cs b/Sample/Behaviors.Sample/App.cs index 12bf6b1..e6c0eb3 100755 --- a/Sample/Behaviors.Sample/App.cs +++ b/Sample/Behaviors.Sample/App.cs @@ -8,7 +8,7 @@ public class App : Application { public App () { - MainPage = new HomePage (); + MainPage = new NavigationPage(new MainPage()); } protected override void OnStart () diff --git a/Sample/Behaviors.Sample/Behaviors.Sample.csproj b/Sample/Behaviors.Sample/Behaviors.Sample.csproj old mode 100755 new mode 100644 index 2b0905f..a24481a --- a/Sample/Behaviors.Sample/Behaviors.Sample.csproj +++ b/Sample/Behaviors.Sample/Behaviors.Sample.csproj @@ -1,113 +1,11 @@ - - - - Debug - AnyCPU - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {63211B14-3CEB-4F12-B447-129BD647AADA} - Library - Behaviors.Sample - Behaviors.Sample - Profile259 - v4.5 - 10.0 - - - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - - HomePage.xaml - - - InvokeCommandDemoPage.xaml - Always - - - InvokeMethodDemoPage.xaml - - - SetPropertyDemoPage.xaml - - - - - - - - - - - AnimationDemoPage.xaml - - - - - - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - - - - - - {98DC638E-301A-4F8E-AF88-5C0C240D24DC} - Behaviors - - - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll - True - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll - True - - - ..\..\packages\Xamarin.Forms.2.2.0.31\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll - True - - - - + - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + netstandard2.0 - - + + + + + + \ No newline at end of file diff --git a/Sample/Behaviors.Sample/Converters/SelectedItemEventArgsToSelectedItemConverter.cs b/Sample/Behaviors.Sample/Converters/SelectedItemEventArgsToSelectedItemConverter.cs index 715b299..d14ee62 100755 --- a/Sample/Behaviors.Sample/Converters/SelectedItemEventArgsToSelectedItemConverter.cs +++ b/Sample/Behaviors.Sample/Converters/SelectedItemEventArgsToSelectedItemConverter.cs @@ -9,7 +9,14 @@ public class SelectedItemEventArgsToSelectedItemConverter : IValueConverter public object Convert (object value, Type targetType, object parameter, CultureInfo culture) { var eventArgs = value as SelectedItemChangedEventArgs; - return eventArgs.SelectedItem; + var person = eventArgs.SelectedItem as Person; + + if (parameter != null) + { + int ageParam = int.Parse(parameter.ToString()); + person = new Person(person.Name, person.Age, ageParam); + } + return person; } public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Sample/Behaviors.Sample/GotoStateDemoPage.xaml b/Sample/Behaviors.Sample/GotoStateDemoPage.xaml new file mode 100644 index 0000000..d286307 --- /dev/null +++ b/Sample/Behaviors.Sample/GotoStateDemoPage.xaml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Sample/Behaviors.Sample/GotoStateDemoPage.xaml.cs b/Sample/Behaviors.Sample/GotoStateDemoPage.xaml.cs new file mode 100644 index 0000000..ae537f4 --- /dev/null +++ b/Sample/Behaviors.Sample/GotoStateDemoPage.xaml.cs @@ -0,0 +1,12 @@ +using Xamarin.Forms; + +namespace Behaviors.Sample +{ + public partial class GotoStateDemoPage : ContentPage + { + public GotoStateDemoPage() + { + InitializeComponent(); + } + } +} diff --git a/Sample/Behaviors.Sample/HomePage.xaml b/Sample/Behaviors.Sample/HomePage.xaml deleted file mode 100755 index dbb42d1..0000000 --- a/Sample/Behaviors.Sample/HomePage.xaml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Sample/Behaviors.Sample/HomePage.xaml.cs b/Sample/Behaviors.Sample/HomePage.xaml.cs deleted file mode 100755 index c3e5dd5..0000000 --- a/Sample/Behaviors.Sample/HomePage.xaml.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Xamarin.Forms; - -namespace Behaviors.Sample -{ - public partial class HomePage : TabbedPage - { - public HomePage () - { - InitializeComponent (); - } - } -} - diff --git a/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml b/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml old mode 100755 new mode 100644 index 763791d..fa4e518 --- a/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml +++ b/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml @@ -1,4 +1,4 @@ - + @@ -16,35 +16,42 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml.cs b/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml.cs index 50c350e..1e95243 100755 --- a/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml.cs +++ b/Sample/Behaviors.Sample/InvokeCommandDemoPage.xaml.cs @@ -6,8 +6,7 @@ public partial class InvokeCommandDemoPage : ContentPage { public InvokeCommandDemoPage () { - InitializeComponent (); + InitializeComponent(); } } } - diff --git a/Sample/Behaviors.Sample/InvokeCommandDemoPageViewModel.cs b/Sample/Behaviors.Sample/InvokeCommandDemoPageViewModel.cs index 6d6cd58..122b34a 100755 --- a/Sample/Behaviors.Sample/InvokeCommandDemoPageViewModel.cs +++ b/Sample/Behaviors.Sample/InvokeCommandDemoPageViewModel.cs @@ -43,7 +43,7 @@ public InvokeCommandDemoPageViewModel () PageDisappearingCommand = new Command (OnPageDisappearing); ItemSelectedCommand = new Command (OutputItemSelected); OutputAgeCommand = new Command (OutputAge); - OutputMessageCommand = new Command (OutputMessage); + OutputMessageCommand = new Command (OutputMessage); } void OnPageAppearing () @@ -58,19 +58,22 @@ void OnPageDisappearing () void OutputItemSelected (Person person) { - SelectedItemText = string.Format ("{0} was selected in the list.", person.Name); + SelectedItemText = string.Format ("{0} is selected in the list.", person.Name); OnPropertyChanged ("SelectedItemText"); } void OutputAge (Person person) { - AgeText = string.Format ("{0} is {1} years old.", person.Name, person.Age); - OnPropertyChanged ("AgeText"); + if (person.AgeParameter > person.Age) + AgeText = string.Format("{0} is {1}. That's younger than {2}.", person.Name, person.Age, person.AgeParameter); + else + AgeText = string.Format("{0} is {1}. That's older than {2}.", person.Name, person.Age, person.AgeParameter); + OnPropertyChanged ("AgeText"); } - void OutputMessage (string text) + void OutputMessage () { - MessageText = string.Format ("Successfully entered {0}", text); + MessageText = "Successfully entered text."; OnPropertyChanged ("MessageText"); } diff --git a/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml b/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml old mode 100755 new mode 100644 index 7fd5562..a5303bd --- a/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml +++ b/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml @@ -1,6 +1,6 @@ - + - + diff --git a/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml.cs b/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml.cs index f8e795a..fbe50b3 100755 --- a/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml.cs +++ b/Sample/Behaviors.Sample/InvokeMethodDemoPage.xaml.cs @@ -5,7 +5,7 @@ namespace Behaviors.Sample { public partial class InvokeMethodDemoPage : ContentPage { - public static readonly BindableProperty CounterProperty = BindableProperty.Create ("Counter", typeof(int), typeof(InvokeMethodDemoPage), default(int)); + public static readonly BindableProperty CounterProperty = BindableProperty.Create (nameof(Counter), typeof(int), typeof(InvokeMethodDemoPage), default(int)); public int Counter { get { return (int)GetValue (CounterProperty); } diff --git a/Sample/Behaviors.Sample/MainPage.xaml b/Sample/Behaviors.Sample/MainPage.xaml new file mode 100644 index 0000000..09482cc --- /dev/null +++ b/Sample/Behaviors.Sample/MainPage.xaml @@ -0,0 +1,20 @@ + + + +