Skip to content

Commit

Permalink
Merge pull request #898 from Yinimi/master
Browse files Browse the repository at this point in the history
Fix activation for nested conductor / screen scenarios
  • Loading branch information
vb2ae authored Nov 11, 2024
2 parents 62c9d8b + 52a65f3 commit bbb73f0
Show file tree
Hide file tree
Showing 29 changed files with 289 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public TabViewModel()
Messages = new BindableCollection<string>();
}

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");

Expand All @@ -35,14 +35,14 @@ protected override Task OnDeactivateAsync(bool close, CancellationToken cancella
return Task.CompletedTask;
}

public override async Task<bool> CanCloseAsync(CancellationToken cancellationToken)
public override async Task<bool> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/scenarios/Scenario.Autofac/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override void Configure()

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
DisplayRootViewFor<ShellViewModel>();
DisplayRootViewForAsync<ShellViewModel>();
}

protected override object GetInstance(Type service, string key)
Expand Down
20 changes: 14 additions & 6 deletions samples/scenarios/Scenario.Autofac/Scenario.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<AssemblyName>Scenario.Autofac</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -127,11 +127,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac">
<Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="Caliburn.Micro">
<Version>3.0.3</Version>
<Version>8.1.1</Version>
</PackageReference>
<Reference Include="Caliburn.Micro.Core, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Core.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Platform.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\uap10.0.19041\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;

namespace Scenario.Autofac.ViewModels
Expand All @@ -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; }
Expand Down
6 changes: 3 additions & 3 deletions samples/scenarios/Scenario.Functional.App/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion samples/scenarios/Scenario.Functional.App/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void Configure()

protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<ShellViewModel>();
DisplayRootViewForAsync<ShellViewModel>();
}

protected override IEnumerable<Assembly> SelectAssemblies()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Scenario.Functional.App</RootNamespace>
<AssemblyName>Scenario.Functional.App</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand All @@ -29,6 +29,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -53,21 +54,17 @@
<StartupObject>Scenario.Functional.App.App</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Caliburn.Micro, Version=3.0.3.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.Core.3.0.3\lib\net45\Caliburn.Micro.dll</HintPath>
<Private>True</Private>
<Reference Include="Caliburn.Micro.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Core.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform, Version=3.0.3.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.dll</HintPath>
<Private>True</Private>
<Reference Include="Caliburn.Micro.Platform">
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Platform.dll</HintPath>
</Reference>
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.0.3.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.0.3\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="Caliburn.Micro.Platform.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETCore\3.7.4.0\FSharp.Core.dll</HintPath>
<Reference Include="FSharp.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\FSharp.Core.8.0.401\lib\netstandard2.0\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -142,18 +139,18 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Scenario.Functional.Core\Scenario.Functional.Core.fsproj">
<Project>{c2e6404f-1a1d-4efc-a87e-933d5a6c7677}</Project>
<Name>Scenario.Functional.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Views\ShellView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Scenario.Functional\Scenario.Functional.fsproj">
<Project>{30005a9b-dbbb-4cd4-a405-8b78a2711202}</Project>
<Name>Scenario.Functional</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
3 changes: 1 addition & 2 deletions samples/scenarios/Scenario.Functional.App/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Caliburn.Micro" version="3.0.3" targetFramework="net452" />
<package id="Caliburn.Micro.Core" version="3.0.3" targetFramework="net452" />
<package id="FSharp.Core" version="8.0.401" targetFramework="net48" />
</packages>
35 changes: 0 additions & 35 deletions samples/scenarios/Scenario.Functional.Core/AssemblyInfo.fs

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions samples/scenarios/Scenario.Functional.Core/packages.config

This file was deleted.

18 changes: 18 additions & 0 deletions samples/scenarios/Scenario.Functional/Scenario.Functional.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>

<ItemGroup>
<Compile Include="ShellViewModel.fs" />
</ItemGroup>

<ItemGroup>
<Reference Include="Caliburn.Micro.Core">
<HintPath>..\..\..\bin\Caliburn.Micro.Platform\release\net462\Caliburn.Micro.Core.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,4 +21,4 @@ type ShellViewModel() =
base.NotifyOfPropertyChange()

member this.SayHello () =
this.DisplayName <- "Hello " + this.Name
this.DisplayName <- "Hello " + this.Name
6 changes: 3 additions & 3 deletions samples/scenarios/Scenario.KeyBinding/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
Loading

0 comments on commit bbb73f0

Please sign in to comment.