Browse Source

Allow styles to apply across popup contexts.

By defining a StylingParent property and tying it to InheritanceParent.
Fixes #312.
Steven Kirk 10 years ago
parent
commit
d004426b28

+ 4 - 0
src/Perspex.Base/Perspex.Base.csproj

@@ -87,6 +87,10 @@
     <Compile Include="Utilities\WeakSubscriptionManager.cs" />
   </ItemGroup>
   <ItemGroup>
+    <Reference Include="JetBrains.Annotations.PCL328, Version=9.2.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
+      <HintPath>..\..\packages\JetBrains.Annotations.9.2.0\lib\portable-net4+sl5+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\JetBrains.Annotations.PCL328.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="System.Reactive.Core">
       <HintPath>..\..\packages\Rx-Core.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Core.dll</HintPath>
     </Reference>

+ 5 - 0
src/Perspex.Controls/Control.cs

@@ -218,6 +218,11 @@ namespace Perspex.Controls
         /// </remarks>
         Type IStyleable.StyleKey => GetType();
 
+        /// <summary>
+        /// Gets the parent style host element.
+        /// </summary>
+        IStyleHost IStyleHost.StylingParent => (IStyleHost)InheritanceParent;
+
         /// <summary>
         /// Gets a value which indicates whether a change to the <see cref="DataContext"/> is in 
         /// the process of being notified.

+ 12 - 0
src/Perspex.Styling/Styling/IStyleHost.cs

@@ -3,8 +3,20 @@
 
 namespace Perspex.Styling
 {
+    /// <summary>
+    /// Defines an element that has a <see cref="Styles"/> collection.
+    /// </summary>
     public interface IStyleHost : IVisual
     {
+        /// <summary>
+        /// Gets the styles for the element.
+        /// </summary>
         Styles Styles { get; }
+
+        /// <summary>
+        /// Gets the parent style host element.
+        /// </summary>
+        IStyleHost StylingParent { get; }
+
     }
 }

+ 1 - 5
src/Perspex.Styling/Styling/Styler.cs

@@ -31,11 +31,7 @@ namespace Perspex.Styling
             Contract.Requires<ArgumentNullException>(control != null);
             Contract.Requires<ArgumentNullException>(container != null);
 
-            IVisual visual = container as IVisual;
-
-            IStyleHost parentContainer = visual?.GetVisualAncestors()
-                .OfType<IStyleHost>()
-                .FirstOrDefault();
+            var parentContainer = container.StylingParent;
 
             if (parentContainer != null)
             {