diff --git a/Perspex.UnitTests/TestRoot.cs b/Perspex.UnitTests/TestRoot.cs index af35faaf71..60df5ed428 100644 --- a/Perspex.UnitTests/TestRoot.cs +++ b/Perspex.UnitTests/TestRoot.cs @@ -9,6 +9,7 @@ namespace Perspex.UnitTests using System; using System.Collections.Generic; using System.Reactive.Disposables; + using Moq; using Perspex.Controls; using Perspex.Layout; @@ -16,12 +17,12 @@ namespace Perspex.UnitTests { public Size ClientSize { - get { throw new NotImplementedException(); } + get { return new Size(100, 100); } } public ILayoutManager LayoutManager { - get { throw new NotImplementedException(); } + get { return new Mock().Object; } } } } diff --git a/Perspex/Controls/TestBorder.cs b/Perspex/Controls/TestBorder.cs deleted file mode 100644 index f143b26820..0000000000 --- a/Perspex/Controls/TestBorder.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Controls -{ - using System; - using System.Reactive.Linq; - using Perspex.Media; - - public class TestBorder : Decorator - { - public override void Render(IDrawingContext context) - { - Brush background = this.Background; - Brush borderBrush = this.BorderBrush; - double borderThickness = this.BorderThickness; - - if (background != null) - { - context.FillRectange(background, new Rect(this.Bounds.Size)); - } - - if (borderBrush != null && borderThickness > 0) - { - context.DrawRectange(new Pen(borderBrush, borderThickness), new Rect(this.Bounds.Size)); - } - } - } -} diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index ed7c7cdbc9..b3f86487de 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -71,7 +71,6 @@ - diff --git a/Perspex/PerspexProperty.cs b/Perspex/PerspexProperty.cs index 4d3ac7c9a8..c3056d1bca 100644 --- a/Perspex/PerspexProperty.cs +++ b/Perspex/PerspexProperty.cs @@ -162,6 +162,11 @@ namespace Perspex this.defaultValues.Add(type, defaultValue); } + + public override string ToString() + { + return this.Name; + } } /// diff --git a/Perspex/Styling/Style.cs b/Perspex/Styling/Style.cs index 3367c171d7..0fc7e98415 100644 --- a/Perspex/Styling/Style.cs +++ b/Perspex/Styling/Style.cs @@ -41,11 +41,14 @@ namespace Perspex.Styling public void Attach(IStyleable control) { string description = "Style " + this.Selector.ToString(); - IObservable activator = this.Selector.GetActivator(control); + StyleActivator activator = this.Selector.GetActivator(control); - foreach (Setter setter in this.Setters) + if (!(activator.CurrentValue == false && activator.HasCompleted)) { - control.SetValue(setter.Property, setter.Value, activator); + foreach (Setter setter in this.Setters) + { + control.SetValue(setter.Property, setter.Value, activator); + } } } } diff --git a/Perspex/Styling/StyleActivator.cs b/Perspex/Styling/StyleActivator.cs index e05a8ab3e1..124021fbb7 100644 --- a/Perspex/Styling/StyleActivator.cs +++ b/Perspex/Styling/StyleActivator.cs @@ -27,8 +27,6 @@ namespace Perspex.Styling List> observers = new List>(); - bool last = false; - public StyleActivator( IEnumerable> inputs, string description, @@ -54,18 +52,30 @@ namespace Perspex.Styling } } + public bool CurrentValue + { + get; + private set; + } + public string Description { get; private set; } + public bool HasCompleted + { + get; + private set; + } + public IDisposable Subscribe(IObserver observer) { Contract.Requires(observer != null); this.observers.Add(observer); - observer.OnNext(last); + observer.OnNext(CurrentValue); return Disposable.Create(() => this.observers.Remove(observer)); } @@ -87,10 +97,10 @@ namespace Perspex.Styling throw new InvalidOperationException("Invalid Activator mode."); } - if (current != last) + if (current != CurrentValue) { this.Push(current); - last = current; + CurrentValue = current; } } @@ -107,6 +117,8 @@ namespace Perspex.Styling { subscription.Dispose(); } + + this.HasCompleted = true; } } diff --git a/Perspex/Styling/Styler.cs b/Perspex/Styling/Styler.cs index 671c8fe948..e56bc9e66c 100644 --- a/Perspex/Styling/Styler.cs +++ b/Perspex/Styling/Styler.cs @@ -18,7 +18,23 @@ namespace Perspex.Styling { IVisual visual = control as IVisual; IStyled styleContainer = visual.GetVisualAncestorOrSelf(); - styleContainer.Styles.Attach(control); + Application.Current.Styles.Attach(control); + this.ApplyStyles(control, styleContainer); + } + + private void ApplyStyles(IStyleable control, IStyled container) + { + if (container != null) + { + IVisual visual = container as IVisual; + + if (visual != null) + { + this.ApplyStyles(control, visual.GetVisualAncestor()); + } + + container.Styles.Attach(control); + } } } } diff --git a/Perspex/Themes/Default/ButtonStyle.cs b/Perspex/Themes/Default/ButtonStyle.cs index df4ff3cadc..2d6e6d3ffd 100644 --- a/Perspex/Themes/Default/ButtonStyle.cs +++ b/Perspex/Themes/Default/ButtonStyle.cs @@ -55,9 +55,6 @@ namespace Perspex.Themes.Default { Border border = new Border(); border.Id = "border"; - border.SetValue(Border.BackgroundProperty, control.GetObservable(Button.BackgroundProperty)); - border.SetValue(Border.BorderBrushProperty, control.GetObservable(Button.BorderBrushProperty)); - border.SetValue(Border.BorderThicknessProperty, control.GetObservable(Button.BorderThicknessProperty)); border.Padding = new Thickness(3); ContentPresenter contentPresenter = new ContentPresenter(); contentPresenter.SetValue(ContentPresenter.ContentProperty, control.GetObservable(Button.ContentProperty)); diff --git a/Perspex/Themes/Default/DefaultTheme.cs b/Perspex/Themes/Default/DefaultTheme.cs index 4c53d9fc0b..daa183be80 100644 --- a/Perspex/Themes/Default/DefaultTheme.cs +++ b/Perspex/Themes/Default/DefaultTheme.cs @@ -11,7 +11,7 @@ namespace Perspex.Themes.Default { public DefaultTheme() { - //this.Add(new ButtonStyle()); + this.Add(new ButtonStyle()); } } } diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index e643cbd68c..fa8f632819 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -50,28 +50,6 @@ namespace TestApplication Window window = new Window { - //Content = new TestBorder - //{ - // Margin = new Thickness(10), - // Styles = new Styles - // { - // new Style(new Selector().OfType()) - // { - // Setters = new[] - // { - // new Setter(TestBorder.BackgroundProperty, new SolidColorBrush(0xff0000ff)), - // } - // }, - // new Style(new Selector().OfType().Class(":mouseover")) - // { - // Setters = new[] - // { - // new Setter(TestBorder.BackgroundProperty, new SolidColorBrush(0xffff0000)), - // } - // }, - // } - //}, - Content = new Button { Content = "Hello World",