Skip to content

Commit

Permalink
Added minor MapApps theme support.
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
Lakritzator committed Jul 26, 2016
1 parent d526b4c commit e221c1e
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 73 deletions.
5 changes: 0 additions & 5 deletions Dapplo.CaliburnMicro.Demo/Dapplo.CaliburnMicro.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
<Compile Include="UseCases\Menu\SaveAsMenuItem.cs" />
<Compile Include="UseCases\Menu\ViewModels\WindowWithMenuViewModel.cs" />
<Compile Include="ViewModels\CredentialsViewModel.cs" />
<Compile Include="ViewModels\DummyViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\LanguageConfigViewModel.cs" />
<Compile Include="ViewModels\NotificationExampleViewModel.cs" />
<Compile Include="UseCases\Configuration\ViewModels\ConfigViewModel.cs" />
Expand Down Expand Up @@ -183,10 +182,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DummyView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UseCases\Configuration\Views\LanguageConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
11 changes: 11 additions & 0 deletions Dapplo.CaliburnMicro.Demo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#region Usings

using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Windows;
using Dapplo.CaliburnMicro.Metro;
using Dapplo.Log.Facade;
using Dapplo.Log.Loggers;

Expand All @@ -38,8 +40,17 @@ namespace Dapplo.CaliburnMicro.Demo
/// <summary>
/// This takes care or starting the Application
/// </summary>
[Export]
public class Startup
{
/// <summary>
/// Example to show how to change the theme, change the following 2 values
/// </summary>
[Export]
public Themes Theme { get; } = Themes.BaseLight;
[Export]
public ThemeAccents ThemeAccent { get; } = ThemeAccents.Orange;

/// <summary>
/// Start the application
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions Dapplo.CaliburnMicro.Demo/ViewModels/CredentialsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public class CredentialsViewModel : Screen
[Import]
public ICredentialsTranslations CredentialsTranslations { get; set; }

[Import]
public DummyViewModel DummyVm { get; set; }

/// <summary>
/// Password for a login
/// </summary>
Expand Down
39 changes: 0 additions & 39 deletions Dapplo.CaliburnMicro.Demo/ViewModels/DummyViewModel.cs

This file was deleted.

1 change: 0 additions & 1 deletion Dapplo.CaliburnMicro.Demo/Views/CredentialsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
<Button x:Name="Login" Content="{Binding CredentialsTranslations.Login}" />
<Button x:Name="Cancel" Content="{Binding CoreTranslations.Cancel}" />
</UniformGrid>
<ContentControl cal:View.Model="{Binding DummyVm}" />
</StackPanel>
</UserControl>
9 changes: 0 additions & 9 deletions Dapplo.CaliburnMicro.Demo/Views/DummyView.xaml

This file was deleted.

2 changes: 2 additions & 0 deletions Dapplo.CaliburnMicro.Metro/Dapplo.CaliburnMicro.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<ItemGroup>
<Compile Include="MetroWindowManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Themes.cs" />
<Compile Include="ThemeAccents.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
43 changes: 30 additions & 13 deletions Dapplo.CaliburnMicro.Metro/MetroWindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Windows;
using System.Windows.Controls;
using Caliburn.Micro;
using MahApps.Metro;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

Expand All @@ -49,24 +50,18 @@ namespace Dapplo.CaliburnMicro.Metro
/// <a href="https://dragablz.net/2015/05/29/using-mahapps-dialog-boxes-in-a-mvvm-setup/">here</a>
/// </summary>
[Export(typeof(IWindowManager))]
public class MetroWindowManager : WindowManager
public class MetroWindowManager : WindowManager, IPartImportsSatisfiedNotification
{
private static readonly string[] Styles =
{
"Colors", "Fonts", "Controls", "Controls.AnimatedSingleRowTabControl", "Accents/Blue",
"Accents/BaseLight"
"Colors", "Fonts", "Controls", "Controls.AnimatedSingleRowTabControl"
};

/// <summary>
/// Add all the resources to the Application
/// </summary>
public MetroWindowManager()
{
foreach (var style in Styles)
{
AddMahappsStyle(style);
}
}
[Import(AllowDefault = true)]
private ThemeAccents ThemeAccent { get; set; }

[Import(AllowDefault = true)]
private Themes Theme { get; set; }

/// <summary>
/// Export the IDialogCoordinator of MahApps, so ViewModels can open MahApps dialogs
Expand Down Expand Up @@ -210,5 +205,27 @@ public static Uri CreateMahappStyleUri(string style)
{
return new Uri($"pack://application:,,,/MahApps.Metro;component/Styles/{style}.xaml", UriKind.RelativeOrAbsolute);
}

/// <summary>
/// Called when a part's imports have been satisfied and it is safe to use.
/// </summary>
public void OnImportsSatisfied()
{
foreach (var style in Styles)
{
AddMahappsStyle(style);
}
if (ThemeAccent == ThemeAccents.Default)
{
ThemeAccent = ThemeAccents.Blue;
}
if (Theme == Themes.Default)
{
Theme = Themes.BaseLight;
}

AddMahappsStyle($"Accents/{ThemeAccent}");
AddMahappsStyle($"Accents/{Theme}");
}
}
}
56 changes: 56 additions & 0 deletions Dapplo.CaliburnMicro.Metro/ThemeAccents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Dapplo - building blocks for desktop applications
// Copyright (C) 2016 Dapplo
//
// For more information see: http://dapplo.net/
// Dapplo repositories are hosted on GitHub: https://github.com/dapplo
//
// This file is part of Dapplo.CaliburnMicro
//
// Dapplo.CaliburnMicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Dapplo.CaliburnMicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have a copy of the GNU Lesser General Public License
// along with Dapplo.CaliburnMicro. If not, see <http://www.gnu.org/licenses/lgpl.txt>.

namespace Dapplo.CaliburnMicro.Metro
{
/// <summary>
/// The accents for MahApps
/// </summary>
public enum ThemeAccents
{
#pragma warning disable 1591
Default,
Amber,
Blue,
Brown,
Cobalt,
Crimso,
Cyan,
Emerald,
Green,
Indigo,
Lime,
Magenta,
Mauve,
Olive,
Orange,
Pink,
Purple,
Red,
Sienna,
Steel,
Taupe,
Teal,
Violet,
Yellow
#pragma warning restore 1591
}
}
35 changes: 35 additions & 0 deletions Dapplo.CaliburnMicro.Metro/Themes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Dapplo - building blocks for desktop applications
// Copyright (C) 2016 Dapplo
//
// For more information see: http://dapplo.net/
// Dapplo repositories are hosted on GitHub: https://github.com/dapplo
//
// This file is part of Dapplo.CaliburnMicro
//
// Dapplo.CaliburnMicro is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Dapplo.CaliburnMicro is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have a copy of the GNU Lesser General Public License
// along with Dapplo.CaliburnMicro. If not, see <http://www.gnu.org/licenses/lgpl.txt>.

namespace Dapplo.CaliburnMicro.Metro
{
/// <summary>
/// The themes for MahApps
/// </summary>
public enum Themes
{
#pragma warning disable 1591
Default,
BaseDark,
BaseLight
#pragma warning restore 1591
}
}
6 changes: 3 additions & 3 deletions Dapplo.CaliburnMicro/Wizard/Views/WizardProgressView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</Style>
<Style TargetType="Path" x:Key="InnerPath" BasedOn="{StaticResource OuterPath}">
<Setter Property="Data" Value="M0.0,0.0 L0.0,0.45 L1.0,0.45 L1.0,0.55 L0.0,0.55 L0.0,1.0"/>
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, Path=Foreground}"/>
<Setter Property="Fill" Value="{StaticResource HighlightBrush}"/>
</Style>
</DataTemplate.Resources>
<Grid SnapsToDevicePixels="True">
Expand All @@ -65,7 +65,7 @@
<Path Name="leftPath" Style="{StaticResource OuterPath}"/>
<Path Grid.Column="1" Name="rightPath" Style="{StaticResource OuterPath}"/>
<Ellipse Grid.ColumnSpan="2" Grid.Column="0" HorizontalAlignment="Center" Stroke="Transparent" Height="20" Width="20" Fill="{StaticResource WizardBarBrush}"/>
<Ellipse Grid.ColumnSpan="2" Grid.Column="0" HorizontalAlignment="Center" Stroke="Transparent" Height="14" Width="14" Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, Path=Foreground}">
<Ellipse Grid.ColumnSpan="2" Grid.Column="0" HorizontalAlignment="Center" Stroke="Transparent" Height="14" Width="14" Fill="{StaticResource HighlightBrush}">
<Ellipse.Visibility>
<MultiBinding Converter="{StaticResource IsProgressedConverter}" ConverterParameter="False">
<Binding RelativeSource="{RelativeSource TemplatedParent}"/>
Expand Down Expand Up @@ -120,7 +120,7 @@
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
<Setter Property="Foreground" Value="Gray"/>
<Setter Property="Foreground" Value="{StaticResource AccentColorBrush4}"/>
<Setter Property="FontStyle" Value="Italic"/>
</DataTrigger>
</Style.Triggers>
Expand Down

0 comments on commit e221c1e

Please sign in to comment.