From 454393b71a154a9bf7f277fa9145362174545965 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Sep 2014 19:51:41 +0200 Subject: [PATCH] Added TabControl. --- Perspex.UnitTests/PerspexObjectTests.cs | 18 +++ .../Styling/SelectorTests_Class.cs | 4 +- .../Styling/SelectorTests_OfType.cs | 4 +- Perspex/ControlExtensions.cs | 37 +++++++ Perspex/Controls/ContentPresenter.cs | 64 ++++++++--- Perspex/Controls/Control.cs | 8 +- Perspex/Controls/Controls.cs | 22 ++++ Perspex/Controls/DataTemplate.cs | 12 +- Perspex/Controls/ItemsControl.cs | 42 +++++++ Perspex/Controls/ItemsPresenter.cs | 18 +-- Perspex/Controls/Panel.cs | 6 +- Perspex/Controls/SelectingItemsControl.cs | 20 ++++ Perspex/Controls/TabControl.cs | 71 ++++++++++++ Perspex/Controls/TabStrip.cs | 42 +++++-- Perspex/Perspex.csproj | 5 + Perspex/PerspexObject.cs | 17 +-- Perspex/PriorityValue.cs | 43 ++++++++ Perspex/Themes/Default/CheckBoxStyle.cs | 2 +- Perspex/Themes/Default/DefaultTheme.cs | 3 +- Perspex/Themes/Default/TabControlStyle.cs | 54 +++++++++ Perspex/Themes/Default/TabItemStyle.cs | 1 - Perspex/Themes/Default/TabStripStyle.cs | 1 + Perspex/VisualExtensions.cs | 1 + TestApplication/Program.cs | 104 +++++++++++------- 24 files changed, 501 insertions(+), 98 deletions(-) create mode 100644 Perspex/ControlExtensions.cs create mode 100644 Perspex/Controls/Controls.cs create mode 100644 Perspex/Controls/SelectingItemsControl.cs create mode 100644 Perspex/Controls/TabControl.cs create mode 100644 Perspex/Themes/Default/TabControlStyle.cs diff --git a/Perspex.UnitTests/PerspexObjectTests.cs b/Perspex.UnitTests/PerspexObjectTests.cs index a79973777a..e8b5c26d43 100644 --- a/Perspex.UnitTests/PerspexObjectTests.cs +++ b/Perspex.UnitTests/PerspexObjectTests.cs @@ -124,6 +124,24 @@ namespace Perspex.UnitTests Class1 target = new Class1(); bool raised = false; + target.SetValue(Class1.FooProperty, "bar"); + + target.PropertyChanged += (s, e) => + { + raised = true; + }; + + target.SetValue(Class1.FooProperty, "bar"); + + Assert.IsFalse(raised); + } + + [TestMethod] + public void SetValue_Doesnt_Raise_PropertyChanged_If_Value_Not_Changed_From_Default() + { + Class1 target = new Class1(); + bool raised = false; + target.PropertyChanged += (s, e) => { raised = true; diff --git a/Perspex.UnitTests/Styling/SelectorTests_Class.cs b/Perspex.UnitTests/Styling/SelectorTests_Class.cs index f9734a7409..3080b68ed2 100644 --- a/Perspex.UnitTests/Styling/SelectorTests_Class.cs +++ b/Perspex.UnitTests/Styling/SelectorTests_Class.cs @@ -52,7 +52,7 @@ namespace Perspex.UnitTests.Styling } [TestMethod] - public void Class_Doesnt_Match_Control_With_TemplatedParent() + public void Class_Matches_Control_With_TemplatedParent() { var control = new Control1 { @@ -62,7 +62,7 @@ namespace Perspex.UnitTests.Styling var target = new Selector().Class("foo"); - Assert.IsFalse(ActivatorValue(target, control)); + Assert.IsTrue(ActivatorValue(target, control)); } [TestMethod] diff --git a/Perspex.UnitTests/Styling/SelectorTests_OfType.cs b/Perspex.UnitTests/Styling/SelectorTests_OfType.cs index 8f8336c81f..c92982010e 100644 --- a/Perspex.UnitTests/Styling/SelectorTests_OfType.cs +++ b/Perspex.UnitTests/Styling/SelectorTests_OfType.cs @@ -44,12 +44,12 @@ namespace Perspex.UnitTests.Styling } [TestMethod] - public void OfType_Doesnt_Match_Control_With_TemplatedParent() + public void OfType_Matches_Control_With_TemplatedParent() { var control = new Control1 { TemplatedParent = new Mock().Object }; var target = new Selector().OfType(); - Assert.IsFalse(ActivatorValue(target, control)); + Assert.IsTrue(ActivatorValue(target, control)); } [TestMethod] diff --git a/Perspex/ControlExtensions.cs b/Perspex/ControlExtensions.cs new file mode 100644 index 0000000000..777aeca917 --- /dev/null +++ b/Perspex/ControlExtensions.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Perspex.Controls; + using Perspex.Styling; + + public static class ControlExtensions + { + public static IEnumerable GetTemplateControls(this ITemplatedControl control) + { + return GetTemplateControls(control, (IVisual)control); + } + + public static IEnumerable GetTemplateControls(ITemplatedControl templated, IVisual parent) + { + IVisual visual = parent as IVisual; + + foreach (IVisual child in visual.VisualChildren.OfType().Where(x => x.TemplatedParent == templated)) + { + yield return (Control)child; + + foreach (IVisual grandchild in GetTemplateControls(templated, child)) + { + yield return (Control)grandchild; + } + } + } + } +} diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs index 0f8dc7d3c9..00158efbab 100644 --- a/Perspex/Controls/ContentPresenter.cs +++ b/Perspex/Controls/ContentPresenter.cs @@ -24,20 +24,20 @@ namespace Perspex.Controls public ContentPresenter() { - this.GetObservableWithHistory(ContentProperty).Subscribe(x => - { - if (x.Item1 is Control) - { - ((IVisual)x.Item1).VisualParent = null; - ((ILogical)x.Item1).LogicalParent = null; - } - - if (x.Item2 is Control) - { - ((IVisual)x.Item2).VisualParent = this; - ((ILogical)x.Item2).LogicalParent = this; - } - }); + this.GetObservableWithHistory(ContentProperty).Subscribe(this.ContentChanged); + //{ + // if (x.Item1 is Control) + // { + // ((IVisual)x.Item1).VisualParent = null; + // ((ILogical)x.Item1).LogicalParent = null; + // } + + // if (x.Item2 is Control) + // { + // ((IVisual)x.Item2).VisualParent = this; + // ((ILogical)x.Item2).LogicalParent = this; + // } + //}); } public object Content @@ -160,5 +160,41 @@ namespace Perspex.Controls return new Size(); } + + private void ContentChanged(Tuple content) + { + if (content.Item1 != null) + { + this.visualChild.VisualParent = null; + ILogical logical = content.Item1 as ILogical; + + if (logical != null) + { + logical.LogicalParent = null; + } + } + + if (content.Item2 != null) + { + IVisual visual = content.Item2 as IVisual; + + if (visual == null) + { + visual = this.GetDataTemplate(content.Item2).Build(content.Item2); + } + + visual.VisualParent = this; + this.visualChild = visual; + + ILogical logical = content.Item2 as ILogical; + + if (logical != null) + { + logical.LogicalParent = (ILogical)this.TemplatedParent; + } + } + + this.InvalidateMeasure(); + } } } diff --git a/Perspex/Controls/Control.cs b/Perspex/Controls/Control.cs index 74e1c85f73..dc26fe7b06 100644 --- a/Perspex/Controls/Control.cs +++ b/Perspex/Controls/Control.cs @@ -214,18 +214,18 @@ namespace Perspex.Controls protected virtual DataTemplate FindDataTemplate(object content) { - IVisual visual = content as IVisual; + Control control = content as Control; - if (visual != null) + if (control != null) { - return new DataTemplate(x => visual); + return new DataTemplate(x => control); } ILogical node = this; while (node != null) { - Control control = node as Control; + control = node as Control; if (control != null) { diff --git a/Perspex/Controls/Controls.cs b/Perspex/Controls/Controls.cs new file mode 100644 index 0000000000..3e0667cc17 --- /dev/null +++ b/Perspex/Controls/Controls.cs @@ -0,0 +1,22 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2013 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +using System.Collections.Generic; + +namespace Perspex.Controls +{ + public class Controls : PerspexList + { + public Controls() + { + } + + public Controls(IEnumerable items) + : base(items) + { + } + } +} diff --git a/Perspex/Controls/DataTemplate.cs b/Perspex/Controls/DataTemplate.cs index 03905d438a..23a925eb97 100644 --- a/Perspex/Controls/DataTemplate.cs +++ b/Perspex/Controls/DataTemplate.cs @@ -14,17 +14,17 @@ namespace Perspex.Controls public static readonly DataTemplate Default = new DataTemplate(typeof(object), o => new TextBlock { Text = o.ToString() }); - public DataTemplate(Func build) + public DataTemplate(Func build) : this(o => true, build) { } - public DataTemplate(Type type, Func build) + public DataTemplate(Type type, Func build) : this(o => type.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo()), build) { } - public DataTemplate(Func match, Func build) + public DataTemplate(Func match, Func build) { Contract.Requires(match != null); Contract.Requires(build != null); @@ -35,17 +35,17 @@ namespace Perspex.Controls public Func Match { get; private set; } - public Func Build { get; private set; } + public Func Build { get; private set; } } public class DataTemplate : DataTemplate { - public DataTemplate(Func build) + public DataTemplate(Func build) : base(typeof(T), o => build((T)o)) { } - public DataTemplate(Func match, Func build) + public DataTemplate(Func match, Func build) : base(o => (o is T) ? match((T)o) : false, o => build((T)o)) { } diff --git a/Perspex/Controls/ItemsControl.cs b/Perspex/Controls/ItemsControl.cs index 4ac836e6f2..b233741ead 100644 --- a/Perspex/Controls/ItemsControl.cs +++ b/Perspex/Controls/ItemsControl.cs @@ -6,7 +6,9 @@ namespace Perspex.Controls { + using System; using System.Collections; + using System.Collections.Generic; public class ItemsControl : TemplatedControl { @@ -22,6 +24,8 @@ namespace Perspex.Controls public static readonly PerspexProperty ItemTemplateProperty = PerspexProperty.Register("ItemTemplate"); + private Dictionary itemControls = new Dictionary(); + public IEnumerable Items { get { return this.GetValue(ItemsProperty); } @@ -39,5 +43,43 @@ namespace Perspex.Controls get { return this.GetValue(ItemTemplateProperty); } set { this.SetValue(ItemTemplateProperty, value); } } + + public Control GetControlForItem(object item) + { + Control result; + this.itemControls.TryGetValue(item, out result); + return result; + } + + public IEnumerable GetAllItemControls() + { + return this.itemControls.Values; + } + + internal Control CreateItemControl(object item) + { + Control control = this.CreateItemControlOverride(item); + this.itemControls.Add(item, control); + return control; + } + + protected virtual Control CreateItemControlOverride(object item) + { + Control control = item as Control; + DataTemplate template = this.ItemTemplate; + + if (control != null) + { + return control; + } + else if (template != null) + { + return template.Build(item); + } + else + { + return this.GetDataTemplate(item).Build(item); + } + } } } diff --git a/Perspex/Controls/ItemsPresenter.cs b/Perspex/Controls/ItemsPresenter.cs index b42b863f22..cb369c3bc3 100644 --- a/Perspex/Controls/ItemsPresenter.cs +++ b/Perspex/Controls/ItemsPresenter.cs @@ -71,27 +71,27 @@ namespace Perspex.Controls return finalSize; } - protected override DataTemplate FindDataTemplate(object content) + private Control CreateItemControl(object item) { - TabItem tabItem = content as TabItem; + ItemsControl i = this.TemplatedParent as ItemsControl; - if (tabItem != null) + if (i != null) { - return new DataTemplate(_ => tabItem); + return i.CreateItemControl(item); } else { - return this.ItemTemplate ?? base.FindDataTemplate(content); + return this.GetDataTemplate(item).Build(item) as Control; } } - - private IEnumerable CreateItems(IEnumerable items) + + private IEnumerable CreateItemControls(IEnumerable items) { if (items != null) { return items .Cast() - .Select(x => this.GetDataTemplate(x).Build(x)) + .Select(x => this.CreateItemControl(x)) .OfType(); } else @@ -116,7 +116,7 @@ namespace Perspex.Controls { if (this.panel != null) { - this.panel.Children = new PerspexList(this.CreateItems(items)); + this.panel.Children = new Controls(this.CreateItemControls(items)); } } } diff --git a/Perspex/Controls/Panel.cs b/Perspex/Controls/Panel.cs index 239c4c32ff..901d30ea44 100644 --- a/Perspex/Controls/Panel.cs +++ b/Perspex/Controls/Panel.cs @@ -19,17 +19,17 @@ namespace Perspex.Controls /// public class Panel : Control, IVisual { - private PerspexList children; + private Controls children; private LogicalChildren logicalChildren; - public PerspexList Children + public Controls Children { get { if (this.children == null) { - this.children = new PerspexList(); + this.children = new Controls(); this.logicalChildren = new LogicalChildren(this, this.children); } diff --git a/Perspex/Controls/SelectingItemsControl.cs b/Perspex/Controls/SelectingItemsControl.cs new file mode 100644 index 0000000000..28ba4ff363 --- /dev/null +++ b/Perspex/Controls/SelectingItemsControl.cs @@ -0,0 +1,20 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Controls +{ + public class SelectingItemsControl : ItemsControl + { + public static readonly PerspexProperty SelectedItemProperty = + PerspexProperty.Register("SelectedItem"); + + public object SelectedItem + { + get { return this.GetValue(SelectedItemProperty); } + set { this.SetValue(SelectedItemProperty, value); } + } + } +} diff --git a/Perspex/Controls/TabControl.cs b/Perspex/Controls/TabControl.cs new file mode 100644 index 0000000000..00270efe4f --- /dev/null +++ b/Perspex/Controls/TabControl.cs @@ -0,0 +1,71 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Controls +{ + using System; + using System.Collections; + using System.Linq; + using System.Reactive.Linq; + + public class TabControl : SelectingItemsControl + { + public static readonly PerspexProperty SelectedContentProperty = + PerspexProperty.Register("SelectedContent"); + + private TabStrip tabStrip; + + public TabControl() + { + this.GetObservable(ItemsProperty).Subscribe(this.ItemsChanged); + this.GetObservable(SelectedItemProperty).Skip(1).Subscribe(this.SelectedItemChanged); + } + + protected override void OnTemplateApplied() + { + this.tabStrip = this.GetTemplateControls() + .OfType() + .FirstOrDefault(); + + if (this.tabStrip != null) + { + this.tabStrip.SelectedItem = this.SelectedItem; + this.tabStrip.GetObservable(TabStrip.SelectedItemProperty).Skip(1).Subscribe(x => + { + this.SelectedItem = x; + }); + } + } + + private void ItemsChanged(IEnumerable items) + { + if (items != null) + { + this.SelectedItem = items.OfType().FirstOrDefault(); + } + else + { + this.SelectedItem = null; + } + } + + private void SelectedItemChanged(object item) + { + this.SelectedItem = item; + + ContentControl content = item as ContentControl; + + if (content != null) + { + this.SetValue(SelectedContentProperty, content.Content); + } + else + { + this.SetValue(SelectedContentProperty, item); + } + } + } +} diff --git a/Perspex/Controls/TabStrip.cs b/Perspex/Controls/TabStrip.cs index 12386f0ec9..67497a04da 100644 --- a/Perspex/Controls/TabStrip.cs +++ b/Perspex/Controls/TabStrip.cs @@ -4,11 +4,12 @@ // // ----------------------------------------------------------------------- -using Perspex.Input; - namespace Perspex.Controls { - public class TabStrip : ItemsControl + using System; + using Perspex.Input; + + public class TabStrip : SelectingItemsControl { private static readonly ItemsPanelTemplate PanelTemplate = new ItemsPanelTemplate( () => new StackPanel()); @@ -25,6 +26,24 @@ namespace Perspex.Controls public TabStrip() { this.PointerPressed += this.OnPointerPressed; + this.GetObservable(SelectedItemProperty).Subscribe(this.SelectedItemChanged); + } + + protected override Control CreateItemControlOverride(object item) + { + TabItem result = item as TabItem; + + if (result == null) + { + result = new TabItem + { + Content = item, + }; + } + + result.IsSelected = this.SelectedItem == item; + + return result; } private void OnPointerPressed(object sender, PointerEventArgs e) @@ -36,16 +55,19 @@ namespace Perspex.Controls { TabItem item = presenter.TemplatedParent as TabItem; - if (item != null && item.TemplatedParent == this) + if (item != null) { - item.IsSelected = true; - - foreach (var i in item.GetVisualSiblings()) - { - i.IsSelected = false; - } + this.SelectedItem = item; } } } + + private void SelectedItemChanged(object selectedItem) + { + foreach (TabItem item in this.GetAllItemControls()) + { + item.IsSelected = item == selectedItem; + } + } } } diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index 80e46c870a..80790baa14 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -71,7 +71,10 @@ + + + @@ -134,6 +137,7 @@ + @@ -205,6 +209,7 @@ + diff --git a/Perspex/PerspexObject.cs b/Perspex/PerspexObject.cs index c3aaab4365..972f88b858 100644 --- a/Perspex/PerspexObject.cs +++ b/Perspex/PerspexObject.cs @@ -412,8 +412,7 @@ namespace Perspex this.GetHashCode(), value)); - v.Clear(Priority); - v.Add(Observable.Never().StartWith(value), Priority); + v.Replace(Observable.Never().StartWith(value), Priority); } /// @@ -455,11 +454,6 @@ namespace Perspex this.values.Add(property, v); } - if (priority == BindingPriority.LocalValue) - { - v.Clear((int)priority); - } - this.Log().Debug(string.Format( "Bound value of {0}.{1} (#{2:x8}) to {3}", this.GetType().Name, @@ -467,7 +461,14 @@ namespace Perspex this.GetHashCode(), description != null ? description.Description : "[Anonymous]")); - return v.Add(source, (int)priority); + if (priority == BindingPriority.LocalValue) + { + return v.Replace(source, (int)priority); + } + else + { + return v.Add(source, (int)priority); + } } /// diff --git a/Perspex/PriorityValue.cs b/Perspex/PriorityValue.cs index 5bcc2c314b..9972b81d68 100644 --- a/Perspex/PriorityValue.cs +++ b/Perspex/PriorityValue.cs @@ -109,6 +109,49 @@ namespace Perspex }); } + /// + /// Adds a new binding, replacing all those of the same priority. + /// + /// The binding. + /// The binding priority. + /// + /// A disposable that will remove the binding. + /// + public IDisposable Replace(IObservable binding, int priority) + { + BindingEntry entry = new BindingEntry(); + LinkedListNode insert = this.bindings.First; + + while (insert != null && insert.Value.Priority < priority) + { + insert = insert.Next; + } + + while (insert != null && insert.Value.Priority == priority) + { + LinkedListNode next = insert.Next; + insert.Value.Dispose(); + this.bindings.Remove(insert); + insert = next; + } + + if (insert == null) + { + this.bindings.AddLast(entry); + } + else + { + this.bindings.AddBefore(insert, entry); + } + + entry.Start(binding, priority, this.EntryChanged, this.EntryCompleted); + + return Disposable.Create(() => + { + this.Remove(entry); + }); + } + /// /// Removes all bindings with the specified priority. /// diff --git a/Perspex/Themes/Default/CheckBoxStyle.cs b/Perspex/Themes/Default/CheckBoxStyle.cs index 206a37a022..b16058f9b2 100644 --- a/Perspex/Themes/Default/CheckBoxStyle.cs +++ b/Perspex/Themes/Default/CheckBoxStyle.cs @@ -56,7 +56,7 @@ namespace Perspex.Themes.Default new ColumnDefinition(GridLength.Auto), new ColumnDefinition(new GridLength(1, GridUnitType.Star)), }, - Children = new PerspexList + Children = new Controls { new Border { diff --git a/Perspex/Themes/Default/DefaultTheme.cs b/Perspex/Themes/Default/DefaultTheme.cs index 2364704493..edec40031a 100644 --- a/Perspex/Themes/Default/DefaultTheme.cs +++ b/Perspex/Themes/Default/DefaultTheme.cs @@ -16,9 +16,10 @@ namespace Perspex.Themes.Default this.Add(new CheckBoxStyle()); this.Add(new ContentControlStyle()); this.Add(new ItemsControlStyle()); - this.Add(new TextBoxStyle()); + this.Add(new TabControlStyle()); this.Add(new TabItemStyle()); this.Add(new TabStripStyle()); + this.Add(new TextBoxStyle()); } } } diff --git a/Perspex/Themes/Default/TabControlStyle.cs b/Perspex/Themes/Default/TabControlStyle.cs new file mode 100644 index 0000000000..b304bef618 --- /dev/null +++ b/Perspex/Themes/Default/TabControlStyle.cs @@ -0,0 +1,54 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Themes.Default +{ + using System.Linq; + using System.Reactive.Linq; + using Perspex.Controls; + using Perspex.Styling; + + public class TabControlStyle : Styles + { + public TabControlStyle() + { + this.AddRange(new[] + { + new Style(x => x.OfType()) + { + Setters = new[] + { + new Setter(TabControl.TemplateProperty, ControlTemplate.Create(this.Template)), + }, + }, + }); + } + + private Control Template(TabControl control) + { + return new Grid + { + RowDefinitions = new RowDefinitions + { + new RowDefinition(GridLength.Auto), + new RowDefinition(new GridLength(1, GridUnitType.Star)), + }, + Children = new Controls + { + new TabStrip + { + [~TabStrip.ItemsProperty] = control[~TabControl.ItemsProperty], + }, + new ContentPresenter + { + [~ContentPresenter.ContentProperty] = control[~TabControl.SelectedContentProperty], + [Grid.RowProperty] = 1, + } + } + }; + } + } +} diff --git a/Perspex/Themes/Default/TabItemStyle.cs b/Perspex/Themes/Default/TabItemStyle.cs index dd0976d6a0..b9929af95d 100644 --- a/Perspex/Themes/Default/TabItemStyle.cs +++ b/Perspex/Themes/Default/TabItemStyle.cs @@ -23,7 +23,6 @@ namespace Perspex.Themes.Default { new Setter(TextBox.FontSizeProperty, 28.7), new Setter(Control.ForegroundProperty, Brushes.Gray), - new Setter(Control.MarginProperty, new Thickness(8, 0)), new Setter(TabItem.TemplateProperty, ControlTemplate.Create(this.Template)), }, }, diff --git a/Perspex/Themes/Default/TabStripStyle.cs b/Perspex/Themes/Default/TabStripStyle.cs index fde473c714..40198c69ab 100644 --- a/Perspex/Themes/Default/TabStripStyle.cs +++ b/Perspex/Themes/Default/TabStripStyle.cs @@ -27,6 +27,7 @@ namespace Perspex.Themes.Default { Setters = new[] { + new Setter(StackPanel.GapProperty, 16.0), new Setter(StackPanel.OrientationProperty, Orientation.Horizontal), }, }, diff --git a/Perspex/VisualExtensions.cs b/Perspex/VisualExtensions.cs index 34988704e3..f6d10b6816 100644 --- a/Perspex/VisualExtensions.cs +++ b/Perspex/VisualExtensions.cs @@ -9,6 +9,7 @@ namespace Perspex using System; using System.Collections.Generic; using System.Linq; + using Perspex.Controls; using Perspex.Styling; public static class VisualExtensions diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 59cf8b57c2..dc505d2a26 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -36,55 +36,85 @@ namespace TestApplication { App application = new App(); - Locator.CurrentMutable.Register(() => new TestLogger { Level = LogLevel.Debug } , typeof(ILogger)); + //Locator.CurrentMutable.Register(() => new TestLogger { Level = LogLevel.Debug } , typeof(ILogger)); Window window = new Window { - Content = new StackPanel + Content = new TabControl { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Orientation = Orientation.Vertical, - Gap = 6, - Children = new PerspexList + Items = new[] { - new Button + new TabItem { - Content = "Button", - }, - new Button - { - Content = "Explict Background", - Background = new SolidColorBrush(0xffa0a0ff), - }, - new CheckBox - { - Content = "Checkbox", - }, - new TextBox - { - Text = "Hello World!", + Header = "Buttons", + Content = new StackPanel + { + Orientation = Orientation.Vertical, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Gap = 8, + MinWidth = 120, + Children = new Controls + { + new Button + { + Content = "Button", + }, + new Button + { + Content = "Button", + Background = new SolidColorBrush(0xcc119eda), + }, + new CheckBox + { + Content = "Checkbox", + }, + } + }, }, - new Image + new TabItem { - Source = new Bitmap("github_icon.png"), - Width = 200, + Header = "Text", + Content = new StackPanel + { + Orientation = Orientation.Vertical, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Gap = 8, + Width = 120, + Children = new Controls + { + new TextBlock + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.", + }, + new TextBox + { + Text = "Text Box", + }, + } + }, }, - new TabStrip + new TabItem { - Items = new[] + Header = "Images", + Content = new StackPanel { - new TabItem - { - Header = "Tab 1", - IsSelected = true, - }, - new TabItem + Orientation = Orientation.Vertical, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Gap = 8, + Width = 120, + Children = new Controls { - Header = "Tab 2", - }, - } - } + new Image + { + Source = new Bitmap("github_icon.png"), + Width = 200, + }, + } + }, + }, } } };