From d004426b28168cd463a529a8067c0c2043f03abe Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 29 Nov 2015 11:39:27 +0100 Subject: [PATCH] Allow styles to apply across popup contexts. By defining a StylingParent property and tying it to InheritanceParent. Fixes #312. --- src/Perspex.Base/Perspex.Base.csproj | 4 ++++ src/Perspex.Controls/Control.cs | 5 +++++ src/Perspex.Styling/Styling/IStyleHost.cs | 12 ++++++++++++ src/Perspex.Styling/Styling/Styler.cs | 6 +----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Perspex.Base/Perspex.Base.csproj b/src/Perspex.Base/Perspex.Base.csproj index 733d8cc69e..4d6504d520 100644 --- a/src/Perspex.Base/Perspex.Base.csproj +++ b/src/Perspex.Base/Perspex.Base.csproj @@ -87,6 +87,10 @@ + + ..\..\packages\JetBrains.Annotations.9.2.0\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\JetBrains.Annotations.PCL328.dll + True + ..\..\packages\Rx-Core.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Core.dll diff --git a/src/Perspex.Controls/Control.cs b/src/Perspex.Controls/Control.cs index 1787742352..861192202b 100644 --- a/src/Perspex.Controls/Control.cs +++ b/src/Perspex.Controls/Control.cs @@ -218,6 +218,11 @@ namespace Perspex.Controls /// Type IStyleable.StyleKey => GetType(); + /// + /// Gets the parent style host element. + /// + IStyleHost IStyleHost.StylingParent => (IStyleHost)InheritanceParent; + /// /// Gets a value which indicates whether a change to the is in /// the process of being notified. diff --git a/src/Perspex.Styling/Styling/IStyleHost.cs b/src/Perspex.Styling/Styling/IStyleHost.cs index cb0da117fb..40cad25f63 100644 --- a/src/Perspex.Styling/Styling/IStyleHost.cs +++ b/src/Perspex.Styling/Styling/IStyleHost.cs @@ -3,8 +3,20 @@ namespace Perspex.Styling { + /// + /// Defines an element that has a collection. + /// public interface IStyleHost : IVisual { + /// + /// Gets the styles for the element. + /// Styles Styles { get; } + + /// + /// Gets the parent style host element. + /// + IStyleHost StylingParent { get; } + } } diff --git a/src/Perspex.Styling/Styling/Styler.cs b/src/Perspex.Styling/Styling/Styler.cs index f1933d5f2e..f2f8f56380 100644 --- a/src/Perspex.Styling/Styling/Styler.cs +++ b/src/Perspex.Styling/Styling/Styler.cs @@ -31,11 +31,7 @@ namespace Perspex.Styling Contract.Requires(control != null); Contract.Requires(container != null); - IVisual visual = container as IVisual; - - IStyleHost parentContainer = visual?.GetVisualAncestors() - .OfType() - .FirstOrDefault(); + var parentContainer = container.StylingParent; if (parentContainer != null) {