From 5f1b9617bb5d5ae4f2426097ff5c4917de257037 Mon Sep 17 00:00:00 2001 From: SuperJMN Date: Sun, 30 Nov 2014 23:36:57 +0100 Subject: [PATCH] Title property for Window --- TestApplication/Program.cs | 1 + Windows/Perspex.Win32/Interop/UnmanagedMethods.cs | 5 ++++- Windows/Perspex.Win32/Window.cs | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index f0b4ed11a9..34720898e5 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -101,6 +101,7 @@ namespace TestApplication Window window = new Window { + Title = "Perspex Test Application", Content = new Grid { RowDefinitions = new RowDefinitions diff --git a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs index bd26a5ca98..0f828526a0 100644 --- a/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs +++ b/Windows/Perspex.Win32/Interop/UnmanagedMethods.cs @@ -444,6 +444,9 @@ namespace Perspex.Win32.Interop IntPtr hInstance, IntPtr lpParam); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern bool SetWindowText(IntPtr hwnd, String lpString); + public struct MSG { public IntPtr hwnd; @@ -483,6 +486,6 @@ namespace Perspex.Win32.Interop public string lpszMenuName; public string lpszClassName; public IntPtr hIconSm; - } + } } } diff --git a/Windows/Perspex.Win32/Window.cs b/Windows/Perspex.Win32/Window.cs index 44cee12b42..a577a64161 100644 --- a/Windows/Perspex.Win32/Window.cs +++ b/Windows/Perspex.Win32/Window.cs @@ -27,6 +27,8 @@ namespace Perspex.Win32 public class Window : ContentControl, ILayoutRoot, IRenderRoot, ICloseable { + public static readonly PerspexProperty TitleProperty = PerspexProperty.Register("Title"); + private UnmanagedMethods.WndProc wndProcDelegate; private string className; @@ -49,7 +51,7 @@ namespace Perspex.Win32 this.LayoutManager.LayoutNeeded.Subscribe(x => { - WindowsDispatcher.CurrentDispatcher.BeginInvoke( + Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Render, () => { @@ -59,11 +61,13 @@ namespace Perspex.Win32 }); }); + this.GetObservable(TitleProperty).Subscribe(s => UnmanagedMethods.SetWindowText(Handle, s)); + this.RenderManager.RenderNeeded .Where(_ => !this.LayoutManager.LayoutQueued) .Subscribe(x => { - WindowsDispatcher.CurrentDispatcher.BeginInvoke( + Dispatcher.CurrentDispatcher.BeginInvoke( DispatcherPriority.Render, () => { @@ -80,6 +84,12 @@ namespace Perspex.Win32 public event EventHandler Closed; + public string Title + { + get { return this.GetValue(TitleProperty); } + set { this.SetValue(TitleProperty, value); } + } + public Size ClientSize { get