Skip to content

Commit

Permalink
Added 3 tool windows for testing in MLibTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirkster99 committed May 7, 2019
1 parent 9d59cc7 commit f435628
Show file tree
Hide file tree
Showing 9 changed files with 629 additions and 6 deletions.
9 changes: 9 additions & 0 deletions source/MLibTest/MLibTest/Demos/PanesTemplateSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows;
using Xceed.Wpf.AvalonDock.Layout;
using AvalonDock.MVVMTestApp;
using AvalonDock.Tools;

/// <summary>
/// Implements a <see ref="DataTemplateSelector"/> for AvalonDock's documents and toolwindows.
Expand Down Expand Up @@ -35,6 +36,11 @@ public PanesTemplateSelector()
/// </summary>
public DataTemplate ColorPickerViewTemplate { get; set; }

/// <summary>
/// Gets a template for simple testing tool windows.
/// </summary>
public DataTemplate Tooln_ViewTemplate { get; set; }

/// <summary>
/// Determines the matching view for a specific given type of viewmodel.
/// </summary>
Expand All @@ -54,6 +60,9 @@ public override System.Windows.DataTemplate SelectTemplate(object item,
if (item is ColorPickerViewModel)
return ColorPickerViewTemplate;

if (item is Tool1_ViewModel || item is Tool2_ViewModel || item is Tool3_ViewModel)
return Tooln_ViewTemplate;

return base.SelectTemplate(item, container);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AvalonDock.MVVMTestApp
namespace AvalonDock.Tools
{
using MLibTest.Demos.ViewModels.Interfaces;
using System;
Expand All @@ -7,8 +7,8 @@
using System.Windows.Input;
using MLibTest.ViewModels.Base;
using MLib.Interfaces;
using System.Windows;
using Settings.Interfaces;
using AvalonDock.MVVMTestApp;

/// <summary>
/// Implements the viewmodel that drives the view a Color Picker tool window.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AvalonDock.MVVMTestApp
namespace AvalonDock.Tools
{
using AvalonDock.MVVMTestApp;
using MLibTest.Demos.ViewModels.Interfaces;
using System;
using System.IO;
Expand Down
184 changes: 184 additions & 0 deletions source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool1_ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
namespace AvalonDock.Tools
{
using MLibTest.Demos.ViewModels.Interfaces;
using System;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows.Input;
using MLibTest.ViewModels.Base;
using MLib.Interfaces;
using Settings.Interfaces;
using AvalonDock.MVVMTestApp;

/// <summary>
/// Implements the viewmodel that drives a sample tool window view.
/// </summary>
internal class Tool1_ViewModel : ToolViewModel
{
#region fields
/// <summary>
/// Identifies the <see ref="ContentId"/> of this tool window.
/// </summary>
public const string ToolContentId = "Tool1_Tool";

/// <summary>
/// Identifies the caption string used for this tool window.
/// </summary>
public const string ToolTitle = "Tool 1";

private IWorkSpaceViewModel _workSpaceViewModel = null;

private Color _SelectedBackgroundColor;
private Color _SelectedAccentColor;
private ICommand _ResetAccentColorCommand;
#endregion fields

#region constructors
/// <summary>
/// Class constructor
/// </summary>
/// <param name="workSpaceViewModel">Is the link to the application's viewmodel
/// to enable (event based) communication between this viewmodel and the application.</param>
public Tool1_ViewModel(IWorkSpaceViewModel workSpaceViewModel)
: base(ToolTitle)
{
_workSpaceViewModel = workSpaceViewModel;

SetupADToolDefaults();
SetupToolDefaults();
}

/// <summary>
/// Hidden default class constructor
/// </summary>
protected Tool1_ViewModel()
: base(ToolTitle)
{
SetupADToolDefaults();
SetupToolDefaults();
}
#endregion constructors

#region properties
/// <summary>
/// Gets/sets the currently selected accent color for the color picker in the tool window's view.
/// </summary>
public Color SelectedBackgroundColor
{
get { return _SelectedBackgroundColor; }
set
{
if (_SelectedBackgroundColor != value)
{
_SelectedBackgroundColor = value;
RaisePropertyChanged(() => SelectedBackgroundColor);
}
}
}

/// <summary>
/// Gets/sets the currently selected accent color for the color picker in the tool window's view.
/// </summary>
public Color SelectedAccentColor
{
get { return _SelectedAccentColor; }
set
{
if (_SelectedAccentColor != value)
{
_SelectedAccentColor = value;
RaisePropertyChanged(() => SelectedAccentColor);
}
}
}

/// <summary>
/// Gets a command to reset the currently selected accent color
/// and reloads all current resources to make sure that the
/// accent is changed consistently.
/// </summary>
public ICommand ResetAccentColorCommand
{
get
{
if (_ResetAccentColorCommand == null)
{
_ResetAccentColorCommand = new RelayCommand<object>((p) =>
{
if ((p is Color) == false)
return;

Color accentColor = (Color)p;

var appearance = GetService<IAppearanceManager>();
var settings = GetService<ISettingsManager>(); // add the default themes

// 1) You could use this if you where using MLib only
// appearance.SetAccentColor(accentColor);

// 2) But you should use this if you use MLib with additional libraries
// with additional accent colors to be synchronized at run-time
appearance.SetTheme(settings.Themes
, appearance.ThemeName
, accentColor);

// 3 You could also use something like this to change accent color
// If you were using your own Theming Framework or MUI, Mahapps etc
//
//// Application.Current.Resources[MWindowLib.Themes.ResourceKeys.ControlAccentColorKey] = accentColor;
//// Application.Current.Resources[MWindowLib.Themes.ResourceKeys.ControlAccentBrushKey] = new SolidColorBrush(accentColor);
////
//// Application.Current.Resources[MLib.Themes.ResourceKeys.ControlAccentColorKey] = accentColor;
//// Application.Current.Resources[MLib.Themes.ResourceKeys.ControlAccentBrushKey] = new SolidColorBrush(accentColor);
////
//// Application.Current.Resources[Xceed.Wpf.AvalonDock.Themes.VS2013.Themes.ResourceKeys.ControlAccentColorKey] = accentColor;
//// Application.Current.Resources[Xceed.Wpf.AvalonDock.Themes.VS2013.Themes.ResourceKeys.ControlAccentBrushKey] = new SolidColorBrush(accentColor);
////
//// Application.Current.Resources[NumericUpDownLib.Themes.ResourceKeys.ControlAccentColorKey] = accentColor;
//// Application.Current.Resources[NumericUpDownLib.Themes.ResourceKeys.ControlAccentBrushKey] = new SolidColorBrush(accentColor);

});
}

return _ResetAccentColorCommand;
}
}

/// <summary>
/// Gets a human readable description for the <see ref="SelectedAccentColor"/> property.
/// </summary>
public string SelectedAccentColorDescription
{
get
{
return "Define a custom color.";
}
}
#endregion properties

#region methods
/// <summary>
/// Initialize Avalondock specific defaults that are specific to this tool window.
/// </summary>
private void SetupADToolDefaults()
{
ContentId = ToolContentId; // Define a unique contentid for this toolwindow

BitmapImage bi = new BitmapImage(); // Define an icon for this toolwindow
bi.BeginInit();
bi.UriSource = new Uri("pack://application:,,/Demos/Images/property-blue.png");
bi.EndInit();
IconSource = bi;
}

/// <summary>
/// Initialize non-Avalondock defaults that are specific to this tool window.
/// </summary>
private void SetupToolDefaults()
{
SelectedBackgroundColor = Color.FromArgb(255, 0, 0, 0);
SelectedAccentColor = Color.FromArgb(128, 0, 180, 0);
}
#endregion methods
}
}
Loading

0 comments on commit f435628

Please sign in to comment.