mirror of https://github.com/AMT-Cheif/Stylet.git
Add Stylet ResourceDictionary, and automatically load on startup
This commit is contained in:
parent
64cdced116
commit
1607dc9ad3
|
@ -5,9 +5,7 @@
|
|||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary>
|
||||
<local:HelloBootstrapper x:Key="bootstrapper"/>
|
||||
</ResourceDictionary>
|
||||
<local:HelloBootstrapper/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
|
|
@ -54,9 +54,6 @@
|
|||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="HelloBootstrapper.cs" />
|
||||
<Compile Include="ShellView.xaml.cs">
|
||||
<DependentUpon>ShellView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ShellViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary>
|
||||
<local:Bootstrapper x:Key="bootstrapper"/>
|
||||
</ResourceDictionary>
|
||||
<local:Bootstrapper/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Stylet.Samples.TabNavigation
|
||||
{
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
xmlns:s="http://github.com/canton7/Stylet"
|
||||
Title="ShellView" Height="300" Width="300">
|
||||
<Grid>
|
||||
<TabControl ItemsSource="{Binding Items}" SelectedItem="{Binding ActiveItem}" DisplayMemberPath="DisplayName">
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
</TabControl>
|
||||
<TabControl Style="{StaticResource StyletConductorTabControl}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
@ -13,11 +13,5 @@ namespace Stylet.Samples.TabNavigation
|
|||
this.ActivateItem(page1);
|
||||
this.Items.Add(page2);
|
||||
}
|
||||
|
||||
public override async Task<bool> CanCloseAsync()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,9 +57,6 @@
|
|||
</ApplicationDefinition>
|
||||
<Compile Include="Page1ViewModel.cs" />
|
||||
<Compile Include="Page2ViewModel.cs" />
|
||||
<Compile Include="ShellView.xaml.cs">
|
||||
<DependentUpon>ShellView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ShellViewModel.cs" />
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Page Include="Page1View.xaml">
|
||||
|
|
|
@ -10,12 +10,30 @@ using System.Windows.Threading;
|
|||
|
||||
namespace Stylet
|
||||
{
|
||||
public class Bootstrapper<TRootViewModel>
|
||||
// We pretend to be a ResourceDictionary so the user can do:
|
||||
// <Application.Resources><ResourceDictionary>
|
||||
// <ResourceDictionary.MergedDictionaries>
|
||||
// <local:Bootstrapper/>
|
||||
// </ResourceDictionary.MergedDictionaries>
|
||||
// </ResourceDictionary></Application.Resources>
|
||||
// rather than:
|
||||
// <Application.Resources><ResourceDictionary>
|
||||
// <ResourceDictionary.MergedDictionaries>
|
||||
// <ResourceDictionary>
|
||||
// <local:Bootstrapper x:Key="bootstrapper"/>
|
||||
// </ResourceDictionary>
|
||||
// </ResourceDictionary.MergedDictionaries>
|
||||
// </ResourceDictionary></Application.Resources>
|
||||
// And also so that we can load the Stylet resources
|
||||
public class Bootstrapper<TRootViewModel> : ResourceDictionary
|
||||
{
|
||||
protected Application Application { get; private set; }
|
||||
|
||||
public Bootstrapper()
|
||||
{
|
||||
var rc = new ResourceDictionary() { Source = new Uri("/Stylet;component/StyletResourceDictionary.xaml", UriKind.Relative) };
|
||||
this.MergedDictionaries.Add(rc);
|
||||
|
||||
this.Start();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Stylet
|
||||
{
|
||||
|
|
|
@ -75,6 +75,12 @@
|
|||
<Compile Include="ViewModelBinder.cs" />
|
||||
<Compile Include="WindowManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="StyletResourceDictionary.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</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.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:Stylet">
|
||||
<Style x:Key="StyletConductorTabControl" TargetType="TabControl">
|
||||
<Setter Property="ItemsSource" Value="{Binding Items}"/>
|
||||
<Setter Property="SelectedItem" Value="{Binding ActiveItem}"/>
|
||||
<Setter Property="DisplayMemberPath" Value="DisplayName"/>
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
Loading…
Reference in New Issue