diff --git a/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs b/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs index 97a8dd9ae..5620f6ae1 100644 --- a/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs +++ b/samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs @@ -14,7 +14,7 @@ public ConductorViewModel() Items.CollectionChanged += (s, e) => NotifyOfPropertyChange(() => CanCloseTab); } - protected override async Task OnInitializeAsync(CancellationToken cancellationToken) + protected override async Task OnInitializedAsync(CancellationToken cancellationToken) { await AddTabAsync(); await AddTabAsync(); diff --git a/samples/features/Features.CrossPlatform.Shared/ViewModels/TabViewModel.cs b/samples/features/Features.CrossPlatform.Shared/ViewModels/TabViewModel.cs index 8655640de..a9814a457 100644 --- a/samples/features/Features.CrossPlatform.Shared/ViewModels/TabViewModel.cs +++ b/samples/features/Features.CrossPlatform.Shared/ViewModels/TabViewModel.cs @@ -14,14 +14,14 @@ public TabViewModel() Messages = new BindableCollection(); } - protected override Task OnInitializeAsync(CancellationToken cancellationToken) + protected override Task OnInitializedAsync(CancellationToken cancellationToken) { Messages.Add("Initialized"); return Task.CompletedTask; } - protected override Task OnActivateAsync(CancellationToken cancellationToken) + protected override Task OnActivatedAsync(CancellationToken cancellationToken) { Messages.Add("Activated"); @@ -35,14 +35,14 @@ protected override Task OnDeactivateAsync(bool close, CancellationToken cancella return Task.CompletedTask; } - public override async Task CanCloseAsync(CancellationToken cancellationToken) + public override async Task CanCloseAsync(CancellationToken cancellationToken = default) { var delay = random.Next(5) + 1; var canClose = random.Next(2) == 0; Messages.Add($"Delaying {delay} seconds and allowing close: {canClose}"); - await Task.Delay(TimeSpan.FromSeconds(delay)); + await Task.Delay(TimeSpan.FromSeconds(delay), cancellationToken); return canClose; } diff --git a/samples/scenarios/Scenario.Autofac/App.xaml.cs b/samples/scenarios/Scenario.Autofac/App.xaml.cs index 55b1b3ac5..f2002da3d 100644 --- a/samples/scenarios/Scenario.Autofac/App.xaml.cs +++ b/samples/scenarios/Scenario.Autofac/App.xaml.cs @@ -26,7 +26,7 @@ protected override void Configure() protected override void OnLaunched(LaunchActivatedEventArgs args) { - DisplayRootViewFor(); + DisplayRootViewForAsync(); } protected override object GetInstance(Type service, string key) diff --git a/samples/scenarios/Scenario.Autofac/Scenario.Autofac.csproj b/samples/scenarios/Scenario.Autofac/Scenario.Autofac.csproj index cfdef9331..938da2e6c 100644 --- a/samples/scenarios/Scenario.Autofac/Scenario.Autofac.csproj +++ b/samples/scenarios/Scenario.Autofac/Scenario.Autofac.csproj @@ -11,8 +11,8 @@ Scenario.Autofac en-US UAP - 10.0.18362.0 - 10.0.18362.0 + 10.0.19041.0 + 10.0.19041.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -127,11 +127,19 @@ - 4.4.0 - - - 3.0.3 + 8.1.1 + + False + ..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Core.dll + + + False + ..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Platform.dll + + + ..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Platform.Core.dll + 6.2.14 diff --git a/samples/scenarios/Scenario.Autofac/ViewModels/ShellViewModel.cs b/samples/scenarios/Scenario.Autofac/ViewModels/ShellViewModel.cs index 434699ad4..1892452af 100644 --- a/samples/scenarios/Scenario.Autofac/ViewModels/ShellViewModel.cs +++ b/samples/scenarios/Scenario.Autofac/ViewModels/ShellViewModel.cs @@ -1,4 +1,6 @@ using System; +using System.Threading; +using System.Threading.Tasks; using Caliburn.Micro; namespace Scenario.Autofac.ViewModels @@ -10,9 +12,10 @@ public ShellViewModel(ChildViewModel child) Child = child; } - protected override void OnInitialize() + protected override Task OnInitializedAsync(CancellationToken cancellationToken) { DisplayName = "Shell"; + return base.OnInitializedAsync(cancellationToken); } public ChildViewModel Child { get; } diff --git a/samples/scenarios/Scenario.Functional.App/App.config b/samples/scenarios/Scenario.Functional.App/App.config index 88fa4027b..4bfa00561 100644 --- a/samples/scenarios/Scenario.Functional.App/App.config +++ b/samples/scenarios/Scenario.Functional.App/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/samples/scenarios/Scenario.Functional.App/Bootstrapper.cs b/samples/scenarios/Scenario.Functional.App/Bootstrapper.cs index d5640b160..ae257320a 100644 --- a/samples/scenarios/Scenario.Functional.App/Bootstrapper.cs +++ b/samples/scenarios/Scenario.Functional.App/Bootstrapper.cs @@ -23,7 +23,7 @@ protected override void Configure() protected override void OnStartup(object sender, StartupEventArgs e) { - DisplayRootViewFor(); + DisplayRootViewForAsync(); } protected override IEnumerable SelectAssemblies() diff --git a/samples/scenarios/Scenario.Functional.App/Properties/Resources.Designer.cs b/samples/scenarios/Scenario.Functional.App/Properties/Resources.Designer.cs index 4be2cd828..ff7b22221 100644 --- a/samples/scenarios/Scenario.Functional.App/Properties/Resources.Designer.cs +++ b/samples/scenarios/Scenario.Functional.App/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Scenario.Functional.App.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/samples/scenarios/Scenario.Functional.App/Properties/Settings.Designer.cs b/samples/scenarios/Scenario.Functional.App/Properties/Settings.Designer.cs index f6c5fd11f..218759ca6 100644 --- a/samples/scenarios/Scenario.Functional.App/Properties/Settings.Designer.cs +++ b/samples/scenarios/Scenario.Functional.App/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Scenario.Functional.App.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/samples/scenarios/Scenario.Functional.App/Scenario.Functional.App.csproj b/samples/scenarios/Scenario.Functional.App/Scenario.Functional.App.csproj index c513701bb..96c71581e 100644 --- a/samples/scenarios/Scenario.Functional.App/Scenario.Functional.App.csproj +++ b/samples/scenarios/Scenario.Functional.App/Scenario.Functional.App.csproj @@ -9,7 +9,7 @@ Properties Scenario.Functional.App Scenario.Functional.App - v4.5.2 + v4.8 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -29,6 +29,7 @@ false false true + AnyCPU @@ -53,21 +54,17 @@ Scenario.Functional.App.App - - ..\packages\Caliburn.Micro.Core.3.0.3\lib\net45\Caliburn.Micro.dll - True + + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Core.dll - - ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.dll - True + + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Platform.dll - - ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.Core.dll - True + + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Platform.Core.dll - - False - C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETCore\3.7.4.0\FSharp.Core.dll + + ..\packages\FSharp.Core.8.0.401\lib\netstandard2.0\FSharp.Core.dll @@ -142,18 +139,18 @@ false - - - {c2e6404f-1a1d-4efc-a87e-933d5a6c7677} - Scenario.Functional.Core - - Designer MSBuild:Compile + + + {30005a9b-dbbb-4cd4-a405-8b78a2711202} + Scenario.Functional + + - \ No newline at end of file diff --git a/samples/scenarios/Scenario.Functional.Core/packages.config b/samples/scenarios/Scenario.Functional.Core/packages.config deleted file mode 100644 index 1c95507b4..000000000 --- a/samples/scenarios/Scenario.Functional.Core/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/samples/scenarios/Scenario.Functional/Scenario.Functional.fsproj b/samples/scenarios/Scenario.Functional/Scenario.Functional.fsproj new file mode 100644 index 000000000..2224bc690 --- /dev/null +++ b/samples/scenarios/Scenario.Functional/Scenario.Functional.fsproj @@ -0,0 +1,18 @@ + + + net48 + + true + 3390;$(WarnOn) + + + + + + + + + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Core.dll + + + diff --git a/samples/scenarios/Scenario.Functional.Core/ShellViewModel.fs b/samples/scenarios/Scenario.Functional/ShellViewModel.fs similarity index 58% rename from samples/scenarios/Scenario.Functional.Core/ShellViewModel.fs rename to samples/scenarios/Scenario.Functional/ShellViewModel.fs index aac4836cd..a650bc1aa 100644 --- a/samples/scenarios/Scenario.Functional.Core/ShellViewModel.fs +++ b/samples/scenarios/Scenario.Functional/ShellViewModel.fs @@ -1,14 +1,18 @@ namespace Scenario.Functional.Core.ViewModels open Caliburn.Micro +open System.Threading.Tasks type ShellViewModel() = inherit Screen() let mutable name = "Enter your name" - override this.OnInitialize () = - this.DisplayName <- "Shell" + override this.OnInitializedAsync (cancellationToken) = + async { + this.DisplayName <- "Shell" + } + |> Async.StartAsTask :> Task member this.Name with get() = name @@ -17,4 +21,4 @@ type ShellViewModel() = base.NotifyOfPropertyChange() member this.SayHello () = - this.DisplayName <- "Hello " + this.Name \ No newline at end of file + this.DisplayName <- "Hello " + this.Name diff --git a/samples/scenarios/Scenario.KeyBinding/App.config b/samples/scenarios/Scenario.KeyBinding/App.config index 88fa4027b..4bfa00561 100644 --- a/samples/scenarios/Scenario.KeyBinding/App.config +++ b/samples/scenarios/Scenario.KeyBinding/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/samples/scenarios/Scenario.KeyBinding/Bootstrapper.cs b/samples/scenarios/Scenario.KeyBinding/Bootstrapper.cs index e96ade94e..d5db813e2 100644 --- a/samples/scenarios/Scenario.KeyBinding/Bootstrapper.cs +++ b/samples/scenarios/Scenario.KeyBinding/Bootstrapper.cs @@ -35,11 +35,11 @@ protected override void Configure() { case "Key": var key = (Key)Enum.Parse(typeof(Key), splits[1], true); - return new KeyTrigger { Key = key }; + return new Microsoft.Xaml.Behaviors.Input.KeyTrigger() { Key = key }; case "Gesture": var mkg = (MultiKeyGesture)(new MultiKeyGestureConverter()).ConvertFrom(splits[1]); - return new KeyTrigger { Modifiers = mkg.KeySequences[0].Modifiers, Key = mkg.KeySequences[0].Keys[0] }; + return new Microsoft.Xaml.Behaviors.Input.KeyTrigger { Modifiers = mkg.KeySequences[0].Modifiers, Key = mkg.KeySequences[0].Keys[0] }; } return defaultCreateTrigger(target, triggerText); @@ -48,7 +48,7 @@ protected override void Configure() protected override void OnStartup(object sender, StartupEventArgs e) { - DisplayRootViewFor(); + DisplayRootViewForAsync(); } } } diff --git a/samples/scenarios/Scenario.KeyBinding/Properties/Resources.Designer.cs b/samples/scenarios/Scenario.KeyBinding/Properties/Resources.Designer.cs index ebe78454a..586082867 100644 --- a/samples/scenarios/Scenario.KeyBinding/Properties/Resources.Designer.cs +++ b/samples/scenarios/Scenario.KeyBinding/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace Scenario.KeyBinding.Properties -{ - - +namespace Scenario.KeyBinding.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace Scenario.KeyBinding.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Scenario.KeyBinding.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/samples/scenarios/Scenario.KeyBinding/Properties/Settings.Designer.cs b/samples/scenarios/Scenario.KeyBinding/Properties/Settings.Designer.cs index 889535b2f..0c96c792f 100644 --- a/samples/scenarios/Scenario.KeyBinding/Properties/Settings.Designer.cs +++ b/samples/scenarios/Scenario.KeyBinding/Properties/Settings.Designer.cs @@ -8,21 +8,17 @@ // //------------------------------------------------------------------------------ -namespace Scenario.KeyBinding.Properties -{ - - +namespace Scenario.KeyBinding.Properties { + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { + + public static Settings Default { + get { return defaultInstance; } } diff --git a/samples/scenarios/Scenario.KeyBinding/Scenario.KeyBinding.csproj b/samples/scenarios/Scenario.KeyBinding/Scenario.KeyBinding.csproj index 66b56fd01..fe07d6578 100644 --- a/samples/scenarios/Scenario.KeyBinding/Scenario.KeyBinding.csproj +++ b/samples/scenarios/Scenario.KeyBinding/Scenario.KeyBinding.csproj @@ -9,11 +9,12 @@ Properties Scenario.KeyBinding Scenario.KeyBinding - v4.5.2 + v4.8 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true + AnyCPU @@ -35,23 +36,27 @@ 4 - - ..\packages\Caliburn.Micro.Core.3.0.3\lib\net45\Caliburn.Micro.dll - True + + False + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Core.dll - - ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.dll - True + + False + ..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Platform.dll - - ..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.Core.dll - True + + ..\..\..\bin\Caliburn.Micro.Platform.Core\release\netstandard2.0\Caliburn.Micro.Platform.Core.dll + + + ..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\Microsoft.Expression.Interactions.dll + + + ..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.135\lib\net462\Microsoft.Xaml.Behaviors.dll - - ..\packages\Caliburn.Micro.3.0.3\lib\net45\System.Windows.Interactivity.dll - True + + ..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll diff --git a/samples/scenarios/Scenario.KeyBinding/packages.config b/samples/scenarios/Scenario.KeyBinding/packages.config index 4f9170d13..14091d083 100644 --- a/samples/scenarios/Scenario.KeyBinding/packages.config +++ b/samples/scenarios/Scenario.KeyBinding/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/samples/scenarios/Scenarios.sln b/samples/scenarios/Scenarios.sln index b72ce8ddd..d78070fab 100644 --- a/samples/scenarios/Scenarios.sln +++ b/samples/scenarios/Scenarios.sln @@ -5,12 +5,12 @@ VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario.Autofac", "Scenario.Autofac\Scenario.Autofac.csproj", "{C1A06169-9A37-479D-A700-21AFEF0B7AD1}" EndProject -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Scenario.Functional.Core", "Scenario.Functional.Core\Scenario.Functional.Core.fsproj", "{C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario.Functional.App", "Scenario.Functional.App\Scenario.Functional.App.csproj", "{CA1175C9-9DD8-4A1C-A3E5-39881E2C81BA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario.KeyBinding", "Scenario.KeyBinding\Scenario.KeyBinding.csproj", "{98DCEBA7-78D0-4F00-9795-1C42DBFC7331}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Scenario.Functional", "Scenario.Functional\Scenario.Functional.fsproj", "{30005A9B-DBBB-4CD4-A405-8B78A2711202}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,22 +45,6 @@ Global {C1A06169-9A37-479D-A700-21AFEF0B7AD1}.Release|x86.ActiveCfg = Release|x86 {C1A06169-9A37-479D-A700-21AFEF0B7AD1}.Release|x86.Build.0 = Release|x86 {C1A06169-9A37-479D-A700-21AFEF0B7AD1}.Release|x86.Deploy.0 = Release|x86 - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|ARM.ActiveCfg = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|ARM.Build.0 = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|x64.ActiveCfg = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|x64.Build.0 = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|x86.ActiveCfg = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Debug|x86.Build.0 = Debug|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|Any CPU.Build.0 = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|ARM.ActiveCfg = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|ARM.Build.0 = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|x64.ActiveCfg = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|x64.Build.0 = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|x86.ActiveCfg = Release|Any CPU - {C2E6404F-1A1D-4EFC-A87E-933D5A6C7677}.Release|x86.Build.0 = Release|Any CPU {CA1175C9-9DD8-4A1C-A3E5-39881E2C81BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CA1175C9-9DD8-4A1C-A3E5-39881E2C81BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {CA1175C9-9DD8-4A1C-A3E5-39881E2C81BA}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -93,6 +77,22 @@ Global {98DCEBA7-78D0-4F00-9795-1C42DBFC7331}.Release|x64.Build.0 = Release|Any CPU {98DCEBA7-78D0-4F00-9795-1C42DBFC7331}.Release|x86.ActiveCfg = Release|Any CPU {98DCEBA7-78D0-4F00-9795-1C42DBFC7331}.Release|x86.Build.0 = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|ARM.ActiveCfg = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|ARM.Build.0 = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|x64.ActiveCfg = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|x64.Build.0 = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|x86.ActiveCfg = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Debug|x86.Build.0 = Debug|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|Any CPU.Build.0 = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|ARM.ActiveCfg = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|ARM.Build.0 = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|x64.ActiveCfg = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|x64.Build.0 = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|x86.ActiveCfg = Release|Any CPU + {30005A9B-DBBB-4CD4-A405-8B78A2711202}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Caliburn.Micro.Core.Tests/ConductorWithCollectionOneActiveTests.cs b/src/Caliburn.Micro.Core.Tests/ConductorWithCollectionOneActiveTests.cs index a176a56a3..60526d04c 100644 --- a/src/Caliburn.Micro.Core.Tests/ConductorWithCollectionOneActiveTests.cs +++ b/src/Caliburn.Micro.Core.Tests/ConductorWithCollectionOneActiveTests.cs @@ -24,6 +24,46 @@ protected override async Task OnDeactivateAsync(bool close, CancellationToken ca } } + private class ConductorExposeChangeActiveItem : Conductor.Collection.OneActive where T : Screen + { + public async Task ChangeActiveItemAsyncPublic(T newItem, bool closePrevious) + { + await ChangeActiveItemAsync(newItem, closePrevious); + } + } + + private class ActivateScreen : Screen + { + public event EventHandler RequestContinue; + + public int ActivateCalledCount { get; private set; } + public bool AutoContinue { get; set; } + + protected override async Task OnActivateAsync(CancellationToken cancellationToken) + { + ActivateCalledCount++; + await Task.Delay(100, cancellationToken); + if (AutoContinue) + RequestContinue?.Invoke(this, EventArgs.Empty); + } + } + + private class ActivatedScreen : Screen + { + public event EventHandler RequestContinue; + + public int ActivateCalledCount { get; private set; } + public bool AutoContinue { get; set; } + + protected override async Task OnActivatedAsync(CancellationToken cancellationToken) + { + ActivateCalledCount++; + await Task.Delay(100, cancellationToken); + if(AutoContinue) + RequestContinue?.Invoke(this, EventArgs.Empty); + } + } + private class AsyncActivationScreen : Screen { private readonly bool _simulateAsyncOnActivate; @@ -40,9 +80,9 @@ public AsyncActivationScreen(bool simulateAsyncOnActivate, bool simulateAsyncOnD _simulateAsyncTaskDuration = simulateAsyncTaskDuration; } - protected override async Task OnActivateAsync(CancellationToken cancellationToken) + protected override async Task OnActivatedAsync(CancellationToken cancellationToken) { - await base.OnActivateAsync(cancellationToken); + await base.OnActivatedAsync(cancellationToken); if (_simulateAsyncOnActivate) { @@ -120,6 +160,82 @@ public async Task ChildrenAreActivatedIfConductorIsActive() Assert.Equal(conducted, conductor.ActiveItem); } + [Fact(Skip = "Please use OnActiveAsync carefully https://github.com/Caliburn-Micro/Caliburn.Micro/issues/789")] + public async Task ActivateWhileActivateOneLevel() + { + var conductor = new Conductor.Collection.OneActive(); + var viewModel1 = new ActivateScreen() + { + DisplayName = "ViewModel 1", + AutoContinue = true + }; + conductor.Items.Add(viewModel1); + var viewModel2 = new ActivateScreen() { DisplayName = "ViewModel 2" }; + conductor.Items.Add(viewModel2); + viewModel1.RequestContinue += (sender, e) => { conductor.ActivateItemAsync(viewModel2).Wait(); }; + + await conductor.ActivateAsync(); + await conductor.ActivateItemAsync(viewModel1); + + Assert.False(viewModel1.IsActive); + Assert.Equal(1, viewModel1.ActivateCalledCount); + Assert.True(viewModel2.IsActive); + Assert.Equal(1, viewModel2.ActivateCalledCount); + } + + [Fact] + public async Task ActivatedWhileActivatedOneLevel() + { + var conductor = new Conductor.Collection.OneActive(); + var viewModel1 = new ActivatedScreen() + { + DisplayName = "ViewModel 1", + AutoContinue = true + }; + conductor.Items.Add(viewModel1); + var viewModel2 = new ActivatedScreen() { DisplayName = "ViewModel 2" }; + conductor.Items.Add(viewModel2); + viewModel1.RequestContinue += (sender, e) => { conductor.ActivateItemAsync(viewModel2).Wait(); }; + + await conductor.ActivateAsync(); + await conductor.ActivateItemAsync(viewModel1); + + Assert.False(viewModel1.IsActive); + Assert.Equal(1, viewModel1.ActivateCalledCount); + Assert.True(viewModel2.IsActive); + Assert.Equal(1, viewModel2.ActivateCalledCount); + } + + [Fact] + public async Task ActivateWhileActivateStackedLevels() + { + var outerConductor = new ConductorExposeChangeActiveItem() { DisplayName = "Outer Conductor" }; + var somePage = new Screen(); + outerConductor.Items.Add(somePage); + var innerConductor = new Conductor.Collection.OneActive() { DisplayName = "Inner Conductor" }; + outerConductor.Items.Add(innerConductor); + var viewModel1 = new ActivatedScreen() { DisplayName = "ViewModel 1" }; + innerConductor.Items.Add(viewModel1); + var viewModel2 = new ActivatedScreen() { DisplayName = "ViewModel 2" }; + innerConductor.Items.Add(viewModel2); + viewModel1.RequestContinue += (sender, e) => { innerConductor.ActivateItemAsync(viewModel2).Wait(); }; + + await outerConductor.ActivateAsync(); + await outerConductor.ActivateItemAsync(innerConductor); + await innerConductor.ActivateItemAsync(viewModel1); + + await outerConductor.ChangeActiveItemAsyncPublic(somePage, false); + Assert.True(somePage.IsActive); + viewModel1.AutoContinue = true; + await outerConductor.ChangeActiveItemAsyncPublic(innerConductor, true); + + Assert.True(innerConductor.IsActive); + Assert.False(viewModel1.IsActive); + Assert.Equal(2, viewModel1.ActivateCalledCount); + Assert.True(viewModel2.IsActive); + Assert.Equal(1, viewModel2.ActivateCalledCount); + } + [Fact(Skip = "ActiveItem currently set regardless of IsActive value. See http://caliburnmicro.codeplex.com/discussions/276375")] public async Task ChildrenAreNotActivatedIfConductorIsNotActive() { diff --git a/src/Caliburn.Micro.Core/Conductor.cs b/src/Caliburn.Micro.Core/Conductor.cs index c95033128..f26295186 100644 --- a/src/Caliburn.Micro.Core/Conductor.cs +++ b/src/Caliburn.Micro.Core/Conductor.cs @@ -52,7 +52,7 @@ public override async Task DeactivateItemAsync(T item, bool close, CancellationT if (closeResult.CloseCanOccur) { - await ChangeActiveItemAsync(default(T), close); + await ChangeActiveItemAsync(default(T), close, cancellationToken); } } @@ -69,10 +69,10 @@ public override async Task DeactivateItemAsync(T item, bool close, CancellationT } /// - /// Called when activating. + /// Called when view has been activated. /// /// A task that represents the asynchronous operation. - protected override Task OnActivateAsync(CancellationToken cancellationToken) + protected override Task OnActivatedAsync(CancellationToken cancellationToken) { return ScreenExtensions.TryActivateAsync(ActiveItem, cancellationToken); } diff --git a/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs b/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs index e2005495f..7fc51b706 100644 --- a/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs +++ b/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs @@ -39,12 +39,13 @@ object IHaveActiveItem.ActiveItem /// A task that represents the asynchronous operation. protected virtual async Task ChangeActiveItemAsync(T newItem, bool closePrevious, CancellationToken cancellationToken) { + var previousItem = _activeItem; newItem = EnsureItem(newItem); _activeItem = newItem; NotifyOfPropertyChange(nameof(ActiveItem)); - await ScreenExtensions.TryDeactivateAsync(_activeItem, closePrevious, cancellationToken); + await ScreenExtensions.TryDeactivateAsync(previousItem, closePrevious, cancellationToken); if (IsActive) await ScreenExtensions.TryActivateAsync(newItem, cancellationToken); diff --git a/src/Caliburn.Micro.Core/ConductorWithCollectionAllActive.cs b/src/Caliburn.Micro.Core/ConductorWithCollectionAllActive.cs index 610dcbea9..34b6dad61 100644 --- a/src/Caliburn.Micro.Core/ConductorWithCollectionAllActive.cs +++ b/src/Caliburn.Micro.Core/ConductorWithCollectionAllActive.cs @@ -65,9 +65,9 @@ public AllActive() public IObservableCollection Items => _items; /// - /// Called when activating. + /// Called when view has been activated. /// - protected override Task OnActivateAsync(CancellationToken cancellationToken) + protected override Task OnActivatedAsync(CancellationToken cancellationToken) { return Task.WhenAll(_items.OfType().Select(x => x.ActivateAsync(cancellationToken))); } @@ -112,9 +112,9 @@ public override async Task CanCloseAsync(CancellationToken cancellationTok } /// - /// Called when initializing. + /// Called when view has been initialized /// - protected override async Task OnInitializeAsync(CancellationToken cancellationToken) + protected override async Task OnInitializedAsync(CancellationToken cancellationToken) { if (_openPublicItems) await Task.WhenAll(GetType().GetRuntimeProperties() diff --git a/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs b/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs index e871e216b..dd3173ec0 100644 --- a/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs +++ b/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs @@ -109,7 +109,7 @@ private async Task CloseItemCoreAsync(T item, CancellationToken cancellationToke var index = _items.IndexOf(item); var next = DetermineNextItemToActivate(_items, index); - await ChangeActiveItemAsync(next, true); + await ChangeActiveItemAsync(next, true, cancellationToken); } else { @@ -164,7 +164,7 @@ public override async Task CanCloseAsync(CancellationToken cancellationTok } while (closable.Contains(next)); var previousActive = ActiveItem; - await ChangeActiveItemAsync(next, true); + await ChangeActiveItemAsync(next, true, cancellationToken); _items.Remove(previousActive); var stillToClose = closable.ToList(); @@ -184,11 +184,11 @@ public override async Task CanCloseAsync(CancellationToken cancellationTok } /// - /// Called when activating. + /// Called when view has been activated. /// /// The cancellation token to cancel operation. /// A task that represents the asynchronous operation. - protected override Task OnActivateAsync(CancellationToken cancellationToken) + protected override Task OnActivatedAsync(CancellationToken cancellationToken) { return ScreenExtensions.TryActivateAsync(ActiveItem, cancellationToken); } diff --git a/src/Caliburn.Micro.Core/Screen.cs b/src/Caliburn.Micro.Core/Screen.cs index 5175e64f3..d9385b728 100644 --- a/src/Caliburn.Micro.Core/Screen.cs +++ b/src/Caliburn.Micro.Core/Screen.cs @@ -102,12 +102,17 @@ async Task IActivate.ActivateAsync(CancellationToken cancellationToken) if (!IsInitialized) { +#pragma warning disable CS0618 // Type or member is obsolete await OnInitializeAsync(cancellationToken); +#pragma warning restore CS0618 // Type or member is obsolete IsInitialized = initialized = true; + await OnInitializedAsync(cancellationToken); } Log.Info("Activating {0}.", this); +#pragma warning disable CS0618 // Type or member is obsolete await OnActivateAsync(cancellationToken); +#pragma warning restore CS0618 // Type or member is obsolete IsActive = true; await OnActivatedAsync(cancellationToken); @@ -173,14 +178,24 @@ public virtual async Task TryCloseAsync(bool? dialogResult = null) /// /// Called when initializing. /// + [Obsolete("Override OnInitializedAsync")] protected virtual Task OnInitializeAsync(CancellationToken cancellationToken) { return Task.FromResult(true); } + /// + /// Called when view has been initialized + /// + protected virtual Task OnInitializedAsync(CancellationToken cancellationToken) + { + return Task.FromResult(true); + } + /// /// Called when activating. /// + [Obsolete("Override OnActivatedAsync")] protected virtual Task OnActivateAsync(CancellationToken cancellationToken) { return Task.FromResult(true);