diff --git a/src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs b/src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs index 1be709216a..31fe2beeeb 100644 --- a/src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs +++ b/src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using JetBrains.Annotations; namespace Perspex.Designer.AppHost @@ -19,6 +20,7 @@ namespace Perspex.Designer.AppHost internal HostedAppModel(PerspexAppHost host) { _host = host; + Background = Settings.Background; } public IntPtr NativeWindowHandle @@ -54,6 +56,17 @@ namespace Perspex.Designer.AppHost } } + public string Background + { + get { return _background; } + set + { + if (value == _background) return; + _background = value; + OnPropertyChanged(); + } + } + public IReadOnlyList AvailableScalingFactors => new List() {1, 2, 4, 8}; public double CurrentScalingFactor @@ -73,6 +86,8 @@ namespace Perspex.Designer.AppHost } double _currentScalingFactor = 1; + private string _color; + private string _background; public event PropertyChangedEventHandler PropertyChanged; diff --git a/src/Windows/Perspex.Designer/AppHost/WindowHost.cs b/src/Windows/Perspex.Designer/AppHost/WindowHost.cs index 549e8a3e79..80b0fe8e9b 100644 --- a/src/Windows/Perspex.Designer/AppHost/WindowHost.cs +++ b/src/Windows/Perspex.Designer/AppHost/WindowHost.cs @@ -20,7 +20,19 @@ namespace Perspex.Designer.AppHost Text = "ScrollableArea"; Controls.Add(_windowHost); _windowHost.Anchor = AnchorStyles.None; - _timer.Tick += delegate { FixWindow(); }; + _timer.Tick += delegate + { + ReloadSettings(); + FixWindow(); + }; + } + + private void ReloadSettings() + { + var bkg = Settings.Background; + var color = System.Drawing.ColorTranslator.FromHtml(bkg); + if (BackColor != color) + BackColor = color; } private Control _windowHost = new Control() {Text = "WindowWrapper"}; @@ -43,6 +55,12 @@ namespace Perspex.Designer.AppHost base.WndProc(ref m); } + protected override void OnPaint(PaintEventArgs e) + { + using (var b = new SolidBrush(BackColor)) + e.Graphics.FillRectangle(b, e.ClipRectangle); + } + void FixPosition() { var newScrollSize = new Size(_desiredWidth, _desiredHeight); diff --git a/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml b/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml index 795749e6f6..721cb83e04 100644 --- a/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml +++ b/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml @@ -16,6 +16,10 @@ + + + diff --git a/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml.cs b/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml.cs index 801b088730..9e617f1560 100644 --- a/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml.cs +++ b/src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml.cs @@ -1,18 +1,21 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; +using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Perspex.Designer.AppHost; +using TextBox = System.Windows.Controls.TextBox; +using UserControl = System.Windows.Controls.UserControl; namespace Perspex.Designer.InProcDesigner { @@ -80,5 +83,16 @@ namespace Perspex.Designer.InProcDesigner }; wnd.ShowDialog(); } + + private void ColorPicker_OnClick(object sender, MouseButtonEventArgs e) + { + var dlg = new ColorDialog() {Color = ColorTranslator.FromHtml(Settings.Background)}; + if (dlg.ShowDialog(_host) == DialogResult.OK) + { + var color = ColorTranslator.ToHtml(dlg.Color); + _appModel.Background = color; + Settings.Background = color; + } + } } } diff --git a/src/Windows/Perspex.Designer/Perspex.Designer.csproj b/src/Windows/Perspex.Designer/Perspex.Designer.csproj index abb50a5279..42131b06fd 100644 --- a/src/Windows/Perspex.Designer/Perspex.Designer.csproj +++ b/src/Windows/Perspex.Designer/Perspex.Designer.csproj @@ -97,6 +97,7 @@ + diff --git a/src/Windows/Perspex.Designer/Settings.cs b/src/Windows/Perspex.Designer/Settings.cs new file mode 100644 index 0000000000..534dd2d5f1 --- /dev/null +++ b/src/Windows/Perspex.Designer/Settings.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Win32; + +namespace Perspex.Designer +{ + static class Settings + { + static readonly string Root = @"HKEY_CURRENT_USER\Software\PerspexUI\Designer"; + public static string Background + { + get { return Registry.GetValue(Root, "Background", "#f3f3f3")?.ToString() ?? "#f3f3f3"; } + set { Registry.SetValue(Root, "Background", value); } + } + } +}