Răsfoiți Sursa

Include default theme and base color in App.paml.

Steven Kirk 9 ani în urmă
părinte
comite
ab2d7571e1

+ 6 - 0
samples/BindingTest/App.paml

@@ -0,0 +1,6 @@
+<Application xmlns="https://github.com/perspex">
+  <Application.Styles>
+    <StyleInclude Source="resm:Perspex.Themes.Default.DefaultTheme.paml?assembly=Perspex.Themes.Default"/>
+    <StyleInclude Source="resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"/>
+  </Application.Styles>
+</Application>

+ 7 - 2
samples/BindingTest/App.cs → samples/BindingTest/App.paml.cs

@@ -2,7 +2,7 @@
 using Perspex;
 using Perspex.Controls;
 using Perspex.Diagnostics;
-using Perspex.Themes.Default;
+using Perspex.Markup.Xaml;
 using Serilog;
 using Serilog.Filters;
 
@@ -14,7 +14,7 @@ namespace BindingTest
         {
             RegisterServices();
             InitializeSubsystems((int)Environment.OSVersion.Platform);
-            Styles = new DefaultTheme();
+            InitializeComponent();
 
             Log.Logger = new LoggerConfiguration()
                 .Filter.ByIncludingOnly(Matching.WithProperty("Area", "Property"))
@@ -36,5 +36,10 @@ namespace BindingTest
             window.Show();
             app.Run(window);
         }
+
+        private void InitializeComponent()
+        {
+            PerspexXamlLoader.Load(this);
+        }
     }
 }

+ 6 - 2
samples/BindingTest/BindingTest.csproj

@@ -74,7 +74,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="App.cs" />
+    <EmbeddedResource Include="App.paml">
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="App.paml.cs">
+      <DependentUpon>App.paml</DependentUpon>
+    </Compile>
     <Compile Include="MainWindow.paml.cs">
       <DependentUpon>MainWindow.paml</DependentUpon>
     </Compile>
@@ -90,7 +95,6 @@
     <None Include="App.config" />
     <EmbeddedResource Include="MainWindow.paml">
       <SubType>Designer</SubType>
-      <Generator>MSBuild:Compile</Generator>
     </EmbeddedResource>
     <None Include="packages.config" />
     <EmbeddedResource Include="TestUserControl.paml" />

+ 3 - 0
samples/ControlCatalog/App.paml

@@ -1,5 +1,8 @@
 <Application xmlns="https://github.com/perspex">
   <Application.Styles>
+    <StyleInclude Source="resm:Perspex.Themes.Default.DefaultTheme.paml?assembly=Perspex.Themes.Default"/>
+    <StyleInclude Source="resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"/>
+
     <Style Selector="TextBlock.h1">
       <Setter Property="Foreground" Value="#212121"/>
       <Setter Property="FontSize" Value="20"/>

+ 0 - 2
samples/ControlCatalog/App.paml.cs

@@ -4,7 +4,6 @@ using Perspex;
 using Perspex.Controls;
 using Perspex.Diagnostics;
 using Perspex.Markup.Xaml;
-using Perspex.Themes.Default;
 using Serilog;
 
 namespace ControlCatalog
@@ -16,7 +15,6 @@ namespace ControlCatalog
             RegisterServices();
             InitializeSubsystems(GetPlatformId());
             InitializeLogging();
-            Styles = new DefaultTheme();
             InitializeComponent();
         }
 

+ 2 - 1
samples/TestApplicationShared/App.cs

@@ -5,6 +5,7 @@ using System;
 using Perspex;
 using Perspex.Controls;
 using Perspex.Controls.Templates;
+using Perspex.Styling;
 using Perspex.Themes.Default;
 
 namespace TestApplication
@@ -15,7 +16,7 @@ namespace TestApplication
         {
             RegisterServices();
             InitializeSubsystems((int)Environment.OSVersion.Platform);            
-            Styles = new DefaultTheme();
+            Styles.Add(new DefaultTheme());
             Styles.Add(new SampleTabStyle());
             DataTemplates = new DataTemplates
             {

+ 0 - 1
samples/XamlTestApplicationPcl/XamlTestApp.cs

@@ -12,7 +12,6 @@ namespace XamlTestApplication
         {
             RegisterServices();
             RegisterPlatform();
-            Styles = new DefaultTheme();
             InitializeComponent();
         }
 

+ 4 - 0
samples/XamlTestApplicationPcl/XamlTestApp.paml

@@ -1,4 +1,8 @@
 <Application x:Class="XamlTestApplicationPcl.XamlTestApp"
         xmlns="https://github.com/perspex"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+  <Application.Styles>
+    <StyleInclude Source="resm:Perspex.Themes.Default.DefaultTheme.paml?assembly=Perspex.Themes.Default"/>
+    <StyleInclude Source="resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"/>
+  </Application.Styles>
 </Application>

+ 1 - 9
src/Perspex.Application/Application.cs

@@ -43,10 +43,6 @@ namespace Perspex
 
         private readonly Lazy<IClipboard> _clipboard =
             new Lazy<IClipboard>(() => (IClipboard)PerspexLocator.Current.GetService(typeof(IClipboard)));
-
-        /// <summary>
-        /// The styler that will be used to apply styles to controls.
-        /// </summary>
         private readonly Styler _styler = new Styler();
 
         /// <summary>
@@ -123,11 +119,7 @@ namespace Perspex
         /// <remarks>
         /// Global styles apply to all windows in the application.
         /// </remarks>
-        public Styles Styles
-        {
-            get;
-            protected set;
-        }
+        public Styles Styles { get; } = new Styles();
 
         /// <summary>
         /// Gets the styling parent of the application, which is null.

+ 8 - 5
src/Perspex.Application/Designer/DesignerAssist.cs

@@ -1,22 +1,20 @@
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Text;
-using System.Threading.Tasks;
 using OmniXaml;
+using OmniXaml.ObjectAssembler;
 using Perspex.Controls;
 using Perspex.Controls.Platform;
 using Perspex.Markup.Xaml;
 using Perspex.Platform;
+using Perspex.Styling;
 using Perspex.Themes.Default;
 
 namespace Perspex.DesignerSupport
 {
-    using OmniXaml.ObjectAssembler;
-
     class DesignerAssist
     {
         class DesignerApp : Application
@@ -26,7 +24,12 @@ namespace Perspex.DesignerSupport
                 RegisterServices();
                 //For now we only support windows
                 InitializeSubsystems(2);
-                Styles = new DefaultTheme();
+                Styles.Add(new DefaultTheme());
+
+                var loader = new PerspexXamlLoader();
+                var baseLight = (IStyle)loader.Load(
+                    new Uri("resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"));
+                Styles.Add(baseLight);
             }
         }
 

+ 0 - 2
src/Perspex.Themes.Default/DefaultTheme.paml

@@ -1,6 +1,4 @@
 <Styles xmlns="https://github.com/perspex">
-  <StyleInclude Source="resm:Perspex.Themes.Default.Accents.BaseLight.paml?assembly=Perspex.Themes.Default"/>
-
   <StyleInclude Source="resm:Perspex.Themes.Default.FocusAdorner.paml?assembly=Perspex.Themes.Default"/>
   <StyleInclude Source="resm:Perspex.Themes.Default.Button.paml?assembly=Perspex.Themes.Default"/>
   <StyleInclude Source="resm:Perspex.Themes.Default.Carousel.paml?assembly=Perspex.Themes.Default"/>

+ 7 - 1
tests/Perspex.UnitTests/UnitTestApplication.cs

@@ -15,7 +15,13 @@ namespace Perspex.UnitTests
         {
             Services = services ?? new TestServices();
             RegisterServices();
-            Styles = Services.Theme?.Invoke();
+
+            var styles = Services.Theme?.Invoke();
+
+            if (styles != null)
+            {
+                Styles.AddRange(styles);
+            }
         }
 
         public static new UnitTestApplication Current => (UnitTestApplication)Application.Current;