Created
August 18, 2015 11:15
-
-
Save tarasn/55079e824b64e4e0e072 to your computer and use it in GitHub Desktop.
Caliburn.Micro+Castle.Windsor navigation example(boilerplate)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application x:Class="CaliburnWpfAppCaliburn.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="clr-namespace:CaliburnWpfAppCaliburn"> | |
<Application.Resources> | |
<ResourceDictionary> | |
<ResourceDictionary.MergedDictionaries> | |
<ResourceDictionary> | |
<local:AppBootstrapper x:Key="bootstrapper" /> | |
</ResourceDictionary> | |
</ResourceDictionary.MergedDictionaries> | |
</ResourceDictionary> | |
</Application.Resources> | |
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Windows; | |
using Caliburn.Micro; | |
using Castle.Windsor; | |
using System.Linq; | |
using Castle.MicroKernel.Registration; | |
namespace CaliburnWpfAppCaliburn | |
{ | |
public class AppBootstrapper : BootstrapperBase | |
{ | |
private IWindsorContainer _container; | |
public AppBootstrapper() | |
{ | |
Initialize(); | |
} | |
protected override void Configure() | |
{ | |
_container = new WindsorContainer(); | |
_container.Register(Component.For<IWindowManager>().ImplementedBy<WindowManager>().LifestyleSingleton()); | |
_container.Register(Component.For<ShellViewModel>().ImplementedBy<ShellViewModel>().LifestyleSingleton()); | |
_container.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>().LifestyleSingleton()); | |
//_container.Singleton<IWindowManager, WindowManager>(); | |
//container.Singleton<IEventAggregator, EventAggregator>(); | |
//container.PerRequest<IScreen, ShellViewModel>(); | |
} | |
protected override object GetInstance(Type service, string key) | |
{ | |
var instance = _container.Resolve(service); | |
if (instance != null) | |
return instance; | |
throw new InvalidOperationException("Could not locate any instances."); | |
} | |
protected override IEnumerable<object> GetAllInstances(Type service) | |
{ | |
var array = _container.ResolveAll(service); | |
object[] trgArray = new object[array.Length]; | |
Array.Copy(array, trgArray, array.Length); | |
return trgArray; | |
} | |
//protected override void BuildUp(object instance) | |
//{ | |
// _container.BuildUp(instance); | |
//} | |
protected override void OnStartup(object sender, StartupEventArgs e) | |
{ | |
DisplayRootViewFor<ShellViewModel>(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="CaliburnWpfAppCaliburn.MyBestView" | |
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" Background="Chocolate"> | |
<Grid> | |
</Grid> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="CaliburnWpfAppCaliburn.ShellView" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | |
<Grid Background="White"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition /> | |
<ColumnDefinition /> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition/> | |
<RowDefinition/> | |
</Grid.RowDefinitions> | |
<Button Grid.Row="0" x:Name="CheckWeb" Content="Check Web" /> | |
<Button Grid.Row="1" x:Name="CheckService" Content="Check Service" /> | |
<ContentControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="ActiveItem" Background="Yellow"/> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Caliburn.Micro; | |
namespace CaliburnWpfAppCaliburn { | |
public class SomeViewModel : Screen | |
{ | |
} | |
public class MyBestViewModel : Screen | |
{ | |
protected override void OnActivate() | |
{ | |
} | |
protected override void OnDeactivate(bool close) | |
{ | |
} | |
} | |
public class ShellViewModel : Conductor<object>.Collection.OneActive | |
{ | |
private readonly IWindowManager _windowManager; | |
private readonly IEventAggregator _eventAggregator; | |
public ShellViewModel(IWindowManager windowManager,IEventAggregator eventAggregator) | |
{ | |
_windowManager = windowManager; | |
_eventAggregator = eventAggregator; | |
} | |
public bool CanCheckWeb() | |
{ | |
return true; | |
} | |
public void CheckWeb() | |
{ | |
this.ActivateItem(new SomeViewModel()); | |
} | |
public bool CanCheckService() | |
{ | |
return true; | |
} | |
public void CheckService() | |
{ | |
this.ActivateItem(new MyBestViewModel()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="CaliburnWpfAppCaliburn.SomeView" | |
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" Background="Blue"> | |
<Grid> | |
</Grid> | |
</UserControl> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment