Browse Source

Added background color for designer

Fixed #183
pull/335/head
Nikita Tsukanov 11 years ago
parent
commit
87b3386e76
  1. 15
      src/Windows/Perspex.Designer/AppHost/HostedAppModel.cs
  2. 20
      src/Windows/Perspex.Designer/AppHost/WindowHost.cs
  3. 4
      src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml
  4. 16
      src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml.cs
  5. 1
      src/Windows/Perspex.Designer/Perspex.Designer.csproj
  6. 19
      src/Windows/Perspex.Designer/Settings.cs

15
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<double> AvailableScalingFactors => new List<double>() {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;

20
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);

4
src/Windows/Perspex.Designer/InProcDesigner/InProcDesignerView.xaml

@ -16,6 +16,10 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Rectangle Cursor="Hand" Stroke="Black" Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}" Fill="{Binding Background}"
Margin="3" MouseDown="ColorPicker_OnClick"/>
<Border x:Name="ErrorPanel" BorderBrush="Red" BorderThickness="3" Padding="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Error}" FontSize="16"/>

16
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;
}
}
}
}

1
src/Windows/Perspex.Designer/Perspex.Designer.csproj

@ -97,6 +97,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="WinApi.cs" />
</ItemGroup>
<ItemGroup>

19
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); }
}
}
}
Loading…
Cancel
Save