diff --git a/Perspex.Controls/DropDown.cs b/Perspex.Controls/DropDown.cs index 45d0b13648..23d48fac8c 100644 --- a/Perspex.Controls/DropDown.cs +++ b/Perspex.Controls/DropDown.cs @@ -35,6 +35,7 @@ namespace Perspex.Controls public DropDown() { this.GetObservableWithHistory(ContentProperty).Subscribe(this.SetContentParent); + this.Bind(ContentProperty, this.GetObservable(DropDown.SelectedItemProperty)); } public object Content @@ -55,6 +56,12 @@ namespace Perspex.Controls set { this.SetValue(VerticalContentAlignmentProperty, value); } } + public bool IsDropDownOpen + { + get { return this.GetValue(IsDropDownOpenProperty); } + set { this.SetValue(IsDropDownOpenProperty, value); } + } + IReadOnlyPerspexList ILogical.LogicalChildren { get { return this.logicalChild; } @@ -76,7 +83,7 @@ namespace Perspex.Controls .Subscribe(x => this.logicalChild.SingleItem = x); } } - + private void SetContentParent(Tuple change) { var control1 = change.Item1 as Control; diff --git a/Perspex.Controls/Popup.cs b/Perspex.Controls/Popup.cs index 8e19f8f9f6..9acd445c6a 100644 --- a/Perspex.Controls/Popup.cs +++ b/Perspex.Controls/Popup.cs @@ -21,6 +21,9 @@ namespace Perspex.Controls public static readonly PerspexProperty PlacementTargetProperty = PerspexProperty.Register("PlacementTarget"); + public static readonly PerspexProperty StaysOpenProperty = + PerspexProperty.Register("StaysOpen", true); + private PopupRoot root; private Window window; @@ -62,6 +65,12 @@ namespace Perspex.Controls set { this.SetValue(PlacementTargetProperty, value); } } + public bool StaysOpen + { + get { return this.GetValue(StaysOpenProperty); } + set { this.SetValue(StaysOpenProperty, value); } + } + public void Open() { if (this.root == null) @@ -69,6 +78,7 @@ namespace Perspex.Controls this.root = new PopupRoot(); this.root.Parent = this; this.root[~PopupRoot.ContentProperty] = this[~ChildProperty]; + this.root.Deactivated += this.RootDeactivated; } this.root.SetPosition(this.GetPosition()); @@ -106,5 +116,13 @@ namespace Perspex.Controls return new Point(); } } + + private void RootDeactivated(object sender, EventArgs e) + { + if (!this.StaysOpen) + { + this.Close(); + } + } } } diff --git a/Perspex.Controls/Primitives/SelectingItemsControl.cs b/Perspex.Controls/Primitives/SelectingItemsControl.cs index f918fd56f1..9106397509 100644 --- a/Perspex.Controls/Primitives/SelectingItemsControl.cs +++ b/Perspex.Controls/Primitives/SelectingItemsControl.cs @@ -125,11 +125,11 @@ namespace Perspex.Controls.Primitives if (selectable != null) { - var container = this.ItemContainerGenerator.GetItemForContainer(selectable); + var item = this.ItemContainerGenerator.GetItemForContainer(selectable); - if (container != null) + if (item != null) { - this.SelectedItem = container; + this.SelectedItem = item; } } } diff --git a/Perspex.Input/MouseDevice.cs b/Perspex.Input/MouseDevice.cs index dd2bc1b1b2..f761bbb02f 100644 --- a/Perspex.Input/MouseDevice.cs +++ b/Perspex.Input/MouseDevice.cs @@ -31,6 +31,11 @@ namespace Perspex.Input .Subscribe(this.ProcessRawEvent); } + public static IMouseDevice Instance + { + get { return Locator.Current.GetService(); } + } + public IInputElement Captured { get; diff --git a/Perspex.Themes.Default/DropDownStyle.cs b/Perspex.Themes.Default/DropDownStyle.cs index 82f1deb8af..7041cdd0ae 100644 --- a/Perspex.Themes.Default/DropDownStyle.cs +++ b/Perspex.Themes.Default/DropDownStyle.cs @@ -84,6 +84,7 @@ namespace Perspex.Themes.Default Child = new ListBox { [~ListBox.ItemsProperty] = control[~DropDown.ItemsProperty], + [~~ListBox.SelectedItemProperty] = control[~~DropDown.SelectedItemProperty], }, PlacementTarget = control, [~Popup.IsOpenProperty] = control[~DropDown.IsDropDownOpenProperty], diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 813eead310..f541da4202 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -170,14 +170,14 @@ namespace TestApplication DevTools.Attach(window); - //var renderer = ((IRenderRoot)window).Renderer; - //var last = renderer.RenderCount; - //DispatcherTimer.Run(() => - //{ - // fps.Text = "FPS: " + (renderer.RenderCount - last); - // last = renderer.RenderCount; - // return true; - //}, TimeSpan.FromSeconds(1)); + var renderer = ((IRenderRoot)window).Renderer; + var last = renderer.RenderCount; + DispatcherTimer.Run(() => + { + fps.Text = "FPS: " + (renderer.RenderCount - last); + last = renderer.RenderCount; + return true; + }, TimeSpan.FromSeconds(1)); window.Show(); Application.Current.Run(window); @@ -362,8 +362,8 @@ namespace TestApplication }, new DropDown { - Content = "Dropdown", Items = listBoxData, + SelectedItem = listBoxData[0], VerticalAlignment = VerticalAlignment.Center, } } diff --git a/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs index 94bd703658..9cc918bbc0 100644 --- a/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs +++ b/Windows/Perspex.Win32/Input/WindowsMouseDevice.cs @@ -15,7 +15,7 @@ namespace Perspex.Win32.Input { private static WindowsMouseDevice instance = new WindowsMouseDevice(); - public static WindowsMouseDevice Instance + public static new WindowsMouseDevice Instance { get { return instance; } } diff --git a/Windows/Perspex.Win32/Win32Platform.cs b/Windows/Perspex.Win32/Win32Platform.cs index a4a58e4fc8..551e218b4c 100644 --- a/Windows/Perspex.Win32/Win32Platform.cs +++ b/Windows/Perspex.Win32/Win32Platform.cs @@ -54,6 +54,7 @@ namespace Perspex.Win32 locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); + locator.Register(() => WindowsMouseDevice.Instance, typeof(IMouseDevice)); locator.Register(() => instance, typeof(IPlatformSettings)); locator.Register(() => instance, typeof(IPlatformThreadingInterface)); }