Skip to content

Commit

Permalink
add hierarchies sample
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed Aug 20, 2023
1 parent d08f5b5 commit 9774347
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Caliburn.Light.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B485A3EA-7A6
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.HelloSpecialValues", "samples\Demo.HelloSpecialValues\Demo.HelloSpecialValues.csproj", "{7864219B-0B4B-4E9C-BC36-D749EE82E214}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Hierarchies", "samples\Demo.Hierarchies\Demo.Hierarchies.csproj", "{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -249,6 +251,26 @@ Global
{7864219B-0B4B-4E9C-BC36-D749EE82E214}.Release|x64.Build.0 = Release|x64
{7864219B-0B4B-4E9C-BC36-D749EE82E214}.Release|x86.ActiveCfg = Release|x86
{7864219B-0B4B-4E9C-BC36-D749EE82E214}.Release|x86.Build.0 = Release|x86
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|ARM.Build.0 = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|arm64.ActiveCfg = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|arm64.Build.0 = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|x64.ActiveCfg = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|x64.Build.0 = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|x86.ActiveCfg = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Debug|x86.Build.0 = Debug|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|Any CPU.Build.0 = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|ARM.ActiveCfg = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|ARM.Build.0 = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|arm64.ActiveCfg = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|arm64.Build.0 = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|x64.ActiveCfg = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|x64.Build.0 = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|x86.ActiveCfg = Release|Any CPU
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -264,6 +286,7 @@ Global
{594FB946-AF74-4020-81F9-75574736905D} = {4B95C303-BF52-4280-9F23-DDBA29E43D07}
{1622C133-84F4-4711-B6B0-97491AA15BF7} = {4B95C303-BF52-4280-9F23-DDBA29E43D07}
{7864219B-0B4B-4E9C-BC36-D749EE82E214} = {4B95C303-BF52-4280-9F23-DDBA29E43D07}
{5494B9C4-D3E1-42DF-9418-2EF9FABC61C1} = {4B95C303-BF52-4280-9F23-DDBA29E43D07}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9B3426B5-9D79-428B-8387-8E2269B14D03}
Expand Down
6 changes: 6 additions & 0 deletions samples/Demo.Hierarchies/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
8 changes: 8 additions & 0 deletions samples/Demo.Hierarchies/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="Demo.Hierarchies.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Demo.Hierarchies">
<Application.Resources>

</Application.Resources>
</Application>
41 changes: 41 additions & 0 deletions samples/Demo.Hierarchies/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Caliburn.Light;
using Caliburn.Light.WPF;
using System.Windows;

namespace Demo.Hierarchies
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private SimpleContainer _container;

public App()
{
_container = new SimpleContainer();

_container.RegisterSingleton<IWindowManager, WindowManager>();
_container.RegisterSingleton<IEventAggregator, EventAggregator>();
_container.RegisterSingleton<IViewModelLocator, ViewModelLocator>();

var typeResolver = new ViewModelTypeResolver()
.AddMapping<ShellView, ShellViewModel>()
.AddMapping<ChildLevel1View, ChildLevel1ViewModel>()
.AddMapping<ChildLevel2View, ChildLevel2ViewModel>();
_container.RegisterInstance<IViewModelTypeResolver>(typeResolver);

_container.RegisterPerRequest<ShellViewModel>();
_container.RegisterPerRequest<ChildLevel1ViewModel>();
_container.RegisterPerRequest<ChildLevel2ViewModel>();
}

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

_container.GetInstance<IWindowManager>()
.ShowWindow(_container.GetInstance<ShellViewModel>());
}
}
}
10 changes: 10 additions & 0 deletions samples/Demo.Hierarchies/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
13 changes: 13 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel1View.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<UserControl x:Class="Demo.Hierarchies.ChildLevel1View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="https://github.com/tibel/Caliburn.Light/"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
DataContext="{Binding ActiveItem, Mode=OneWay}"
cal:View.Create="True" />
</UserControl>
15 changes: 15 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel1View.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Controls;

namespace Demo.Hierarchies
{
/// <summary>
/// Interaction logic for ChildLevel1View.xaml
/// </summary>
public partial class ChildLevel1View : UserControl
{
public ChildLevel1View()
{
InitializeComponent();
}
}
}
12 changes: 12 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel1ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Caliburn.Light;

namespace Demo.Hierarchies
{
public class ChildLevel1ViewModel : Conductor<Screen>.Collection.OneActive
{
public ChildLevel1ViewModel(ChildLevel2ViewModel child)
{
ActiveItem = child;
}
}
}
11 changes: 11 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel2View.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<UserControl x:Class="Demo.Hierarchies.ChildLevel2View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Border Background="Aquamarine"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</UserControl>
15 changes: 15 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel2View.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Controls;

namespace Demo.Hierarchies
{
/// <summary>
/// Interaction logic for ChildLevel2View.xaml
/// </summary>
public partial class ChildLevel2View : UserControl
{
public ChildLevel2View()
{
InitializeComponent();
}
}
}
8 changes: 8 additions & 0 deletions samples/Demo.Hierarchies/ChildLevel2ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Caliburn.Light;

namespace Demo.Hierarchies
{
public class ChildLevel2ViewModel : Screen
{
}
}
11 changes: 11 additions & 0 deletions samples/Demo.Hierarchies/Demo.Hierarchies.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Caliburn.Light.Core\Caliburn.Light.Core.csproj" />
<ProjectReference Include="..\..\src\Caliburn.Light.WPF\Caliburn.Light.WPF.csproj" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions samples/Demo.Hierarchies/ShellView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Window x:Class="Demo.Hierarchies.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="https://github.com/tibel/Caliburn.Light/"
Title="Demo.Hierarchies" Height="350" Width="525">
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
DataContext="{Binding ActiveItem, Mode=OneWay}"
cal:View.Create="True" />
</Window>
15 changes: 15 additions & 0 deletions samples/Demo.Hierarchies/ShellView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows;

namespace Demo.Hierarchies
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class ShellView : Window
{
public ShellView()
{
InitializeComponent();
}
}
}
12 changes: 12 additions & 0 deletions samples/Demo.Hierarchies/ShellViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Caliburn.Light;

namespace Demo.Hierarchies
{
public class ShellViewModel : Conductor<ChildLevel1ViewModel>.Collection.OneActive
{
public ShellViewModel(ChildLevel1ViewModel child)
{
ActiveItem = child;
}
}
}

0 comments on commit 9774347

Please sign in to comment.