Browse Source

Handle dropdown selection.

pull/39/head
Steven Kirk 12 years ago
parent
commit
374d1723a2
  1. 9
      Perspex.Controls/DropDown.cs
  2. 18
      Perspex.Controls/Popup.cs
  3. 6
      Perspex.Controls/Primitives/SelectingItemsControl.cs
  4. 5
      Perspex.Input/MouseDevice.cs
  5. 1
      Perspex.Themes.Default/DropDownStyle.cs
  6. 18
      TestApplication/Program.cs
  7. 2
      Windows/Perspex.Win32/Input/WindowsMouseDevice.cs
  8. 1
      Windows/Perspex.Win32/Win32Platform.cs

9
Perspex.Controls/DropDown.cs

@ -35,6 +35,7 @@ namespace Perspex.Controls
public DropDown() public DropDown()
{ {
this.GetObservableWithHistory(ContentProperty).Subscribe(this.SetContentParent); this.GetObservableWithHistory(ContentProperty).Subscribe(this.SetContentParent);
this.Bind(ContentProperty, this.GetObservable(DropDown.SelectedItemProperty));
} }
public object Content public object Content
@ -55,6 +56,12 @@ namespace Perspex.Controls
set { this.SetValue(VerticalContentAlignmentProperty, value); } set { this.SetValue(VerticalContentAlignmentProperty, value); }
} }
public bool IsDropDownOpen
{
get { return this.GetValue(IsDropDownOpenProperty); }
set { this.SetValue(IsDropDownOpenProperty, value); }
}
IReadOnlyPerspexList<ILogical> ILogical.LogicalChildren IReadOnlyPerspexList<ILogical> ILogical.LogicalChildren
{ {
get { return this.logicalChild; } get { return this.logicalChild; }
@ -76,7 +83,7 @@ namespace Perspex.Controls
.Subscribe(x => this.logicalChild.SingleItem = x); .Subscribe(x => this.logicalChild.SingleItem = x);
} }
} }
private void SetContentParent(Tuple<object, object> change) private void SetContentParent(Tuple<object, object> change)
{ {
var control1 = change.Item1 as Control; var control1 = change.Item1 as Control;

18
Perspex.Controls/Popup.cs

@ -21,6 +21,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<Control> PlacementTargetProperty = public static readonly PerspexProperty<Control> PlacementTargetProperty =
PerspexProperty.Register<Popup, Control>("PlacementTarget"); PerspexProperty.Register<Popup, Control>("PlacementTarget");
public static readonly PerspexProperty<bool> StaysOpenProperty =
PerspexProperty.Register<Popup, bool>("StaysOpen", true);
private PopupRoot root; private PopupRoot root;
private Window window; private Window window;
@ -62,6 +65,12 @@ namespace Perspex.Controls
set { this.SetValue(PlacementTargetProperty, value); } set { this.SetValue(PlacementTargetProperty, value); }
} }
public bool StaysOpen
{
get { return this.GetValue(StaysOpenProperty); }
set { this.SetValue(StaysOpenProperty, value); }
}
public void Open() public void Open()
{ {
if (this.root == null) if (this.root == null)
@ -69,6 +78,7 @@ namespace Perspex.Controls
this.root = new PopupRoot(); this.root = new PopupRoot();
this.root.Parent = this; this.root.Parent = this;
this.root[~PopupRoot.ContentProperty] = this[~ChildProperty]; this.root[~PopupRoot.ContentProperty] = this[~ChildProperty];
this.root.Deactivated += this.RootDeactivated;
} }
this.root.SetPosition(this.GetPosition()); this.root.SetPosition(this.GetPosition());
@ -106,5 +116,13 @@ namespace Perspex.Controls
return new Point(); return new Point();
} }
} }
private void RootDeactivated(object sender, EventArgs e)
{
if (!this.StaysOpen)
{
this.Close();
}
}
} }
} }

6
Perspex.Controls/Primitives/SelectingItemsControl.cs

@ -125,11 +125,11 @@ namespace Perspex.Controls.Primitives
if (selectable != null) 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;
} }
} }
} }

5
Perspex.Input/MouseDevice.cs

@ -31,6 +31,11 @@ namespace Perspex.Input
.Subscribe(this.ProcessRawEvent); .Subscribe(this.ProcessRawEvent);
} }
public static IMouseDevice Instance
{
get { return Locator.Current.GetService<IMouseDevice>(); }
}
public IInputElement Captured public IInputElement Captured
{ {
get; get;

1
Perspex.Themes.Default/DropDownStyle.cs

@ -84,6 +84,7 @@ namespace Perspex.Themes.Default
Child = new ListBox Child = new ListBox
{ {
[~ListBox.ItemsProperty] = control[~DropDown.ItemsProperty], [~ListBox.ItemsProperty] = control[~DropDown.ItemsProperty],
[~~ListBox.SelectedItemProperty] = control[~~DropDown.SelectedItemProperty],
}, },
PlacementTarget = control, PlacementTarget = control,
[~Popup.IsOpenProperty] = control[~DropDown.IsDropDownOpenProperty], [~Popup.IsOpenProperty] = control[~DropDown.IsDropDownOpenProperty],

18
TestApplication/Program.cs

@ -170,14 +170,14 @@ namespace TestApplication
DevTools.Attach(window); DevTools.Attach(window);
//var renderer = ((IRenderRoot)window).Renderer; var renderer = ((IRenderRoot)window).Renderer;
//var last = renderer.RenderCount; var last = renderer.RenderCount;
//DispatcherTimer.Run(() => DispatcherTimer.Run(() =>
//{ {
// fps.Text = "FPS: " + (renderer.RenderCount - last); fps.Text = "FPS: " + (renderer.RenderCount - last);
// last = renderer.RenderCount; last = renderer.RenderCount;
// return true; return true;
//}, TimeSpan.FromSeconds(1)); }, TimeSpan.FromSeconds(1));
window.Show(); window.Show();
Application.Current.Run(window); Application.Current.Run(window);
@ -362,8 +362,8 @@ namespace TestApplication
}, },
new DropDown new DropDown
{ {
Content = "Dropdown",
Items = listBoxData, Items = listBoxData,
SelectedItem = listBoxData[0],
VerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
} }
} }

2
Windows/Perspex.Win32/Input/WindowsMouseDevice.cs

@ -15,7 +15,7 @@ namespace Perspex.Win32.Input
{ {
private static WindowsMouseDevice instance = new WindowsMouseDevice(); private static WindowsMouseDevice instance = new WindowsMouseDevice();
public static WindowsMouseDevice Instance public static new WindowsMouseDevice Instance
{ {
get { return instance; } get { return instance; }
} }

1
Windows/Perspex.Win32/Win32Platform.cs

@ -54,6 +54,7 @@ namespace Perspex.Win32
locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => new PopupImpl(), typeof(IPopupImpl));
locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); locator.Register(() => new WindowImpl(), typeof(IWindowImpl));
locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice));
locator.Register(() => WindowsMouseDevice.Instance, typeof(IMouseDevice));
locator.Register(() => instance, typeof(IPlatformSettings)); locator.Register(() => instance, typeof(IPlatformSettings));
locator.Register(() => instance, typeof(IPlatformThreadingInterface)); locator.Register(() => instance, typeof(IPlatformThreadingInterface));
} }

Loading…
Cancel
Save