Browse Source

Now showing exception happened inside designer process when parsing xaml

pull/148/head
Nikita Tsukanov 11 years ago
parent
commit
3eab3d4b99
  1. 18
      src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs
  2. 31
      src/Windows/Perspex.Designer/AppHost/WindowHost.cs
  3. 7
      src/Windows/Perspex.Designer/Comm/ProcessHost.cs
  4. 5
      src/Windows/Perspex.Designer/WinApi.cs

18
src/Windows/Perspex.Designer/AppHost/PerspexAppHost.cs

@ -46,11 +46,19 @@ namespace Perspex.Designer.AppHost
{
if(!_initSuccess)
return;
dynamic window = Activator.CreateInstance(LookupType("Perspex.Controls.Window"));
_xamlReader(new MemoryStream(Encoding.UTF8.GetBytes(xaml)), window);
var hWnd = (IntPtr) window.PlatformImpl.Handle;
_host.SetWindow(hWnd);
window.Show();
try
{
dynamic window = Activator.CreateInstance(LookupType("Perspex.Controls.Window"));
_xamlReader(new MemoryStream(Encoding.UTF8.GetBytes(xaml)), window);
var hWnd = (IntPtr) window.PlatformImpl.Handle;
_host.SetWindow(hWnd);
window.Show();
}
catch(Exception e)
{
_host.SetWindow(IntPtr.Zero);
_host.PlaceholderText = e.ToString();
}
}
void UpdateState(string state)

31
src/Windows/Perspex.Designer/AppHost/WindowHost.cs

@ -13,26 +13,43 @@ namespace Perspex.Designer.AppHost
{
public WindowHost()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
BackColor = Color.AliceBlue;
_textBox = new TextBox {Dock = DockStyle.Fill, ReadOnly = true, Multiline = true, Visible = false};
Controls.Add(_textBox);
}
private IntPtr _hWnd;
private TextBox _textBox;
protected override void OnPaint(PaintEventArgs e)
public string PlaceholderText
{
e.Graphics.FillRectangle(Brushes.AliceBlue, ClientRectangle);
get { return _textBox.Text; }
set
{
_textBox.Text = value;
FixWindow();
}
}
private IntPtr _hWnd;
public void SetWindow(IntPtr hWnd)
{
if (_hWnd != IntPtr.Zero)
WinApi.SendMessage(_hWnd, WinApi.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_hWnd = hWnd;
WinApi.SetParent(hWnd, Handle);
FixWindow();
if (_hWnd != IntPtr.Zero)
{
WinApi.SetParent(hWnd, Handle);
FixWindow();
}
}
void FixWindow()
{
WinApi.MoveWindow(_hWnd, 0, 0, Width, Height, true);
if (_hWnd != IntPtr.Zero)
WinApi.MoveWindow(_hWnd, 0, 0, Width, Height, true);
_textBox.Visible = _hWnd == IntPtr.Zero && !string.IsNullOrWhiteSpace(_textBox.Text);
}
protected override void OnResize(EventArgs e)

7
src/Windows/Perspex.Designer/Comm/ProcessHost.cs

@ -65,6 +65,7 @@ namespace Perspex.Designer.Comm
void OnExited(object sender, EventArgs eventArgs)
{
_comm.Dispose();
_proc = null;
_dispatcher.Post(_ =>
{
IsAlive = false;
@ -78,7 +79,11 @@ namespace Perspex.Designer.Comm
if (_proc != null)
{
_proc.Exited -= OnExited;
_proc.Kill();
try
{
_proc.Kill();
}
catch { }
OnExited(null, null);
State = "Restarting...";
}

5
src/Windows/Perspex.Designer/WinApi.cs

@ -13,5 +13,10 @@ namespace Perspex.Designer
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll")]
public static extern bool SetParent(IntPtr hWnd, IntPtr hWndNewParent);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public const uint WM_CLOSE = 0x0010;
}
}

Loading…
Cancel
Save