diff --git a/source/MLibTest/MLibTest/Demos/PanesTemplateSelector.cs b/source/MLibTest/MLibTest/Demos/PanesTemplateSelector.cs index 3480fba8..ddfe94bc 100644 --- a/source/MLibTest/MLibTest/Demos/PanesTemplateSelector.cs +++ b/source/MLibTest/MLibTest/Demos/PanesTemplateSelector.cs @@ -4,6 +4,7 @@ using System.Windows; using Xceed.Wpf.AvalonDock.Layout; using AvalonDock.MVVMTestApp; + using AvalonDock.Tools; /// /// Implements a for AvalonDock's documents and toolwindows. @@ -35,6 +36,11 @@ public PanesTemplateSelector() /// public DataTemplate ColorPickerViewTemplate { get; set; } + /// + /// Gets a template for simple testing tool windows. + /// + public DataTemplate Tooln_ViewTemplate { get; set; } + /// /// Determines the matching view for a specific given type of viewmodel. /// @@ -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); } } diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/ColorPickerViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/ColorPickerViewModel.cs similarity index 99% rename from source/MLibTest/MLibTest/Demos/ViewModels/ColorPickerViewModel.cs rename to source/MLibTest/MLibTest/Demos/ViewModels/Tools/ColorPickerViewModel.cs index 096b6360..580db7e7 100644 --- a/source/MLibTest/MLibTest/Demos/ViewModels/ColorPickerViewModel.cs +++ b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/ColorPickerViewModel.cs @@ -1,4 +1,4 @@ -namespace AvalonDock.MVVMTestApp +namespace AvalonDock.Tools { using MLibTest.Demos.ViewModels.Interfaces; using System; @@ -7,8 +7,8 @@ using System.Windows.Input; using MLibTest.ViewModels.Base; using MLib.Interfaces; - using System.Windows; using Settings.Interfaces; + using AvalonDock.MVVMTestApp; /// /// Implements the viewmodel that drives the view a Color Picker tool window. diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/AD/FileStatsViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/FileStatsViewModel.cs similarity index 98% rename from source/MLibTest/MLibTest/Demos/ViewModels/AD/FileStatsViewModel.cs rename to source/MLibTest/MLibTest/Demos/ViewModels/Tools/FileStatsViewModel.cs index 28596f35..4c9f2fca 100644 --- a/source/MLibTest/MLibTest/Demos/ViewModels/AD/FileStatsViewModel.cs +++ b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/FileStatsViewModel.cs @@ -1,5 +1,6 @@ -namespace AvalonDock.MVVMTestApp +namespace AvalonDock.Tools { + using AvalonDock.MVVMTestApp; using MLibTest.Demos.ViewModels.Interfaces; using System; using System.IO; diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool1_ViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool1_ViewModel.cs new file mode 100644 index 00000000..b1cc29da --- /dev/null +++ b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool1_ViewModel.cs @@ -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; + + /// + /// Implements the viewmodel that drives a sample tool window view. + /// + internal class Tool1_ViewModel : ToolViewModel + { + #region fields + /// + /// Identifies the of this tool window. + /// + public const string ToolContentId = "Tool1_Tool"; + + /// + /// Identifies the caption string used for this tool window. + /// + public const string ToolTitle = "Tool 1"; + + private IWorkSpaceViewModel _workSpaceViewModel = null; + + private Color _SelectedBackgroundColor; + private Color _SelectedAccentColor; + private ICommand _ResetAccentColorCommand; + #endregion fields + + #region constructors + /// + /// Class constructor + /// + /// Is the link to the application's viewmodel + /// to enable (event based) communication between this viewmodel and the application. + public Tool1_ViewModel(IWorkSpaceViewModel workSpaceViewModel) + : base(ToolTitle) + { + _workSpaceViewModel = workSpaceViewModel; + + SetupADToolDefaults(); + SetupToolDefaults(); + } + + /// + /// Hidden default class constructor + /// + protected Tool1_ViewModel() + : base(ToolTitle) + { + SetupADToolDefaults(); + SetupToolDefaults(); + } + #endregion constructors + + #region properties + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedBackgroundColor + { + get { return _SelectedBackgroundColor; } + set + { + if (_SelectedBackgroundColor != value) + { + _SelectedBackgroundColor = value; + RaisePropertyChanged(() => SelectedBackgroundColor); + } + } + } + + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedAccentColor + { + get { return _SelectedAccentColor; } + set + { + if (_SelectedAccentColor != value) + { + _SelectedAccentColor = value; + RaisePropertyChanged(() => SelectedAccentColor); + } + } + } + + /// + /// Gets a command to reset the currently selected accent color + /// and reloads all current resources to make sure that the + /// accent is changed consistently. + /// + public ICommand ResetAccentColorCommand + { + get + { + if (_ResetAccentColorCommand == null) + { + _ResetAccentColorCommand = new RelayCommand((p) => + { + if ((p is Color) == false) + return; + + Color accentColor = (Color)p; + + var appearance = GetService(); + var settings = GetService(); // 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; + } + } + + /// + /// Gets a human readable description for the property. + /// + public string SelectedAccentColorDescription + { + get + { + return "Define a custom color."; + } + } + #endregion properties + + #region methods + /// + /// Initialize Avalondock specific defaults that are specific to this tool window. + /// + 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; + } + + /// + /// Initialize non-Avalondock defaults that are specific to this tool window. + /// + private void SetupToolDefaults() + { + SelectedBackgroundColor = Color.FromArgb(255, 0, 0, 0); + SelectedAccentColor = Color.FromArgb(128, 0, 180, 0); + } + #endregion methods + } +} diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool2_ViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool2_ViewModel.cs new file mode 100644 index 00000000..09e1e1d8 --- /dev/null +++ b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool2_ViewModel.cs @@ -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; + + /// + /// Implements the viewmodel that drives a sample tool window view. + /// + internal class Tool2_ViewModel : ToolViewModel + { + #region fields + /// + /// Identifies the of this tool window. + /// + public const string ToolContentId = "Tool2_Tool"; + + /// + /// Identifies the caption string used for this tool window. + /// + public const string ToolTitle = "Tool 2"; + + private IWorkSpaceViewModel _workSpaceViewModel = null; + + private Color _SelectedBackgroundColor; + private Color _SelectedAccentColor; + private ICommand _ResetAccentColorCommand; + #endregion fields + + #region constructors + /// + /// Class constructor + /// + /// Is the link to the application's viewmodel + /// to enable (event based) communication between this viewmodel and the application. + public Tool2_ViewModel(IWorkSpaceViewModel workSpaceViewModel) + : base(ToolTitle) + { + _workSpaceViewModel = workSpaceViewModel; + + SetupADToolDefaults(); + SetupToolDefaults(); + } + + /// + /// Hidden default class constructor + /// + protected Tool2_ViewModel() + : base(ToolTitle) + { + SetupADToolDefaults(); + SetupToolDefaults(); + } + #endregion constructors + + #region properties + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedBackgroundColor + { + get { return _SelectedBackgroundColor; } + set + { + if (_SelectedBackgroundColor != value) + { + _SelectedBackgroundColor = value; + RaisePropertyChanged(() => SelectedBackgroundColor); + } + } + } + + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedAccentColor + { + get { return _SelectedAccentColor; } + set + { + if (_SelectedAccentColor != value) + { + _SelectedAccentColor = value; + RaisePropertyChanged(() => SelectedAccentColor); + } + } + } + + /// + /// Gets a command to reset the currently selected accent color + /// and reloads all current resources to make sure that the + /// accent is changed consistently. + /// + public ICommand ResetAccentColorCommand + { + get + { + if (_ResetAccentColorCommand == null) + { + _ResetAccentColorCommand = new RelayCommand((p) => + { + if ((p is Color) == false) + return; + + Color accentColor = (Color)p; + + var appearance = GetService(); + var settings = GetService(); // 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; + } + } + + /// + /// Gets a human readable description for the property. + /// + public string SelectedAccentColorDescription + { + get + { + return "Define a custom color."; + } + } + #endregion properties + + #region methods + /// + /// Initialize Avalondock specific defaults that are specific to this tool window. + /// + 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; + } + + /// + /// Initialize non-Avalondock defaults that are specific to this tool window. + /// + private void SetupToolDefaults() + { + SelectedBackgroundColor = Color.FromArgb(255, 0, 0, 0); + SelectedAccentColor = Color.FromArgb(128, 0, 180, 0); + } + #endregion methods + } +} diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool3_ViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool3_ViewModel.cs new file mode 100644 index 00000000..57f3f245 --- /dev/null +++ b/source/MLibTest/MLibTest/Demos/ViewModels/Tools/Tool3_ViewModel.cs @@ -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; + + /// + /// Implements the viewmodel that drives a sample tool window view. + /// + internal class Tool3_ViewModel : ToolViewModel + { + #region fields + /// + /// Identifies the of this tool window. + /// + public const string ToolContentId = "Tool3_Tool"; + + /// + /// Identifies the caption string used for this tool window. + /// + public const string ToolTitle = "Tool 3"; + + private IWorkSpaceViewModel _workSpaceViewModel = null; + + private Color _SelectedBackgroundColor; + private Color _SelectedAccentColor; + private ICommand _ResetAccentColorCommand; + #endregion fields + + #region constructors + /// + /// Class constructor + /// + /// Is the link to the application's viewmodel + /// to enable (event based) communication between this viewmodel and the application. + public Tool3_ViewModel(IWorkSpaceViewModel workSpaceViewModel) + : base(ToolTitle) + { + _workSpaceViewModel = workSpaceViewModel; + + SetupADToolDefaults(); + SetupToolDefaults(); + } + + /// + /// Hidden default class constructor + /// + protected Tool3_ViewModel() + : base(ToolTitle) + { + SetupADToolDefaults(); + SetupToolDefaults(); + } + #endregion constructors + + #region properties + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedBackgroundColor + { + get { return _SelectedBackgroundColor; } + set + { + if (_SelectedBackgroundColor != value) + { + _SelectedBackgroundColor = value; + RaisePropertyChanged(() => SelectedBackgroundColor); + } + } + } + + /// + /// Gets/sets the currently selected accent color for the color picker in the tool window's view. + /// + public Color SelectedAccentColor + { + get { return _SelectedAccentColor; } + set + { + if (_SelectedAccentColor != value) + { + _SelectedAccentColor = value; + RaisePropertyChanged(() => SelectedAccentColor); + } + } + } + + /// + /// Gets a command to reset the currently selected accent color + /// and reloads all current resources to make sure that the + /// accent is changed consistently. + /// + public ICommand ResetAccentColorCommand + { + get + { + if (_ResetAccentColorCommand == null) + { + _ResetAccentColorCommand = new RelayCommand((p) => + { + if ((p is Color) == false) + return; + + Color accentColor = (Color)p; + + var appearance = GetService(); + var settings = GetService(); // 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; + } + } + + /// + /// Gets a human readable description for the property. + /// + public string SelectedAccentColorDescription + { + get + { + return "Define a custom color."; + } + } + #endregion properties + + #region methods + /// + /// Initialize Avalondock specific defaults that are specific to this tool window. + /// + 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; + } + + /// + /// Initialize non-Avalondock defaults that are specific to this tool window. + /// + private void SetupToolDefaults() + { + SelectedBackgroundColor = Color.FromArgb(255, 0, 0, 0); + SelectedAccentColor = Color.FromArgb(128, 0, 180, 0); + } + #endregion methods + } +} diff --git a/source/MLibTest/MLibTest/Demos/ViewModels/WorkSpaceViewModel.cs b/source/MLibTest/MLibTest/Demos/ViewModels/WorkSpaceViewModel.cs index 7e0fb191..9f0d8575 100644 --- a/source/MLibTest/MLibTest/Demos/ViewModels/WorkSpaceViewModel.cs +++ b/source/MLibTest/MLibTest/Demos/ViewModels/WorkSpaceViewModel.cs @@ -1,6 +1,7 @@ namespace MLibTest.Demos.ViewModels { using AvalonDock.MVVMTestApp; + using AvalonDock.Tools; using Microsoft.Win32; using MLibTest.Demos.ViewModels.Interfaces; using MLibTest.ViewModels.Base; @@ -100,6 +101,9 @@ internal class WorkSpaceViewModel : MLibTest.ViewModels.Base.ViewModelBase, IWor private FileStatsViewModel _fileStats = null; private ColorPickerViewModel _ColorPicker = null; + private Tool1_ViewModel _Tool1; + private Tool2_ViewModel _Tool2; + private Tool3_ViewModel _Tool3; private FileViewModel _activeDocument = null; #endregion private fields @@ -163,7 +167,7 @@ public IEnumerable Tools get { if (_tools == null) - _tools = new ToolViewModel[] { FileStats, ColorPicker }; + _tools = new ToolViewModel[] { FileStats, ColorPicker, Tool1, Tool2, Tool3 }; return _tools; } } @@ -196,6 +200,48 @@ public ColorPickerViewModel ColorPicker } } + /// + /// Gets an instance of the tool1 tool window viewmodel. + /// + public Tool1_ViewModel Tool1 + { + get + { + if (_Tool1 == null) + _Tool1 = new Tool1_ViewModel(this as IWorkSpaceViewModel); + + return _Tool1; + } + } + + /// + /// Gets an instance of the tool2 tool window viewmodel. + /// + public Tool2_ViewModel Tool2 + { + get + { + if (_Tool2 == null) + _Tool2 = new Tool2_ViewModel(this as IWorkSpaceViewModel); + + return _Tool2; + } + } + + /// + /// Gets an instance of the tool3 tool window viewmodel. + /// + public Tool3_ViewModel Tool3 + { + get + { + if (_Tool3 == null) + _Tool3 = new Tool3_ViewModel(this as IWorkSpaceViewModel); + + return _Tool3; + } + } + /// /// Gets a open document command to open files from the file system. /// diff --git a/source/MLibTest/MLibTest/MLibTest.csproj b/source/MLibTest/MLibTest/MLibTest.csproj index 02019a38..59d9e339 100644 --- a/source/MLibTest/MLibTest/MLibTest.csproj +++ b/source/MLibTest/MLibTest/MLibTest.csproj @@ -81,12 +81,15 @@ - - + + + + + ColorSelectionView.xaml diff --git a/source/MLibTest/MLibTest/MainWindow.xaml b/source/MLibTest/MLibTest/MainWindow.xaml index 8a17a304..77faea7f 100644 --- a/source/MLibTest/MLibTest/MainWindow.xaml +++ b/source/MLibTest/MLibTest/MainWindow.xaml @@ -67,6 +67,9 @@ + + + @@ -107,6 +110,15 @@ + + + + + + + + +