Skip to content

Commit

Permalink
Merge pull request #5 from SuperJMN/title-for-window
Browse files Browse the repository at this point in the history
Title property for Window
  • Loading branch information
grokys committed Nov 30, 2014
2 parents 6644676 + 5f1b961 commit d6fd795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions TestApplication/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static void Main(string[] args)

Window window = new Window
{
Title = "Perspex Test Application",
Content = new Grid
{
RowDefinitions = new RowDefinitions
Expand Down
5 changes: 4 additions & 1 deletion Windows/Perspex.Win32/Interop/UnmanagedMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ public static extern IntPtr CreateWindowEx(
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;
Expand Down Expand Up @@ -483,6 +486,6 @@ public struct WNDCLASSEX
public string lpszMenuName;
public string lpszClassName;
public IntPtr hIconSm;
}
}
}
}
14 changes: 12 additions & 2 deletions Windows/Perspex.Win32/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace Perspex.Win32

public class Window : ContentControl, ILayoutRoot, IRenderRoot, ICloseable
{
public static readonly PerspexProperty<string> TitleProperty = PerspexProperty.Register<Window, string>("Title");

private UnmanagedMethods.WndProc wndProcDelegate;

private string className;
Expand All @@ -49,7 +51,7 @@ public Window()

this.LayoutManager.LayoutNeeded.Subscribe(x =>
{
WindowsDispatcher.CurrentDispatcher.BeginInvoke(
Dispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Render,
() =>
{
Expand All @@ -59,11 +61,13 @@ public Window()
});
});

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,
() =>
{
Expand All @@ -80,6 +84,12 @@ public Window()

public event EventHandler Closed;

public string Title
{
get { return this.GetValue(TitleProperty); }
set { this.SetValue(TitleProperty, value); }
}

public Size ClientSize
{
get
Expand Down

0 comments on commit d6fd795

Please sign in to comment.