Bläddra i källkod

Added basic support for control templates in XAML.

Still need TemplateBinding markup extension.
Steven Kirk 10 år sedan
förälder
incheckning
08f067b983

+ 17 - 0
samples/XamlTestApplicationPcl/XamlTestApp.paml

@@ -1,4 +1,21 @@
 <Application x:Class="XamlTestApplicationPcl.XamlTestApp"
         xmlns="https://github.com/perspex"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+  <Application.Styles>
+    <Style Selector="Button">
+      <Setter Property="Button.Background" Value="#ffaaaaaa"/>
+      <Setter Property="Button.BorderBrush" Value="#ffaaaaaa"/>
+      <Setter Property="Button.BorderThickness" Value="2"/>
+      <Setter Property="Button.Foreground" Value="Black"/>
+      <Setter Property="Button.HorizontalContentAlignment" Value="Center"/>
+      <Setter Property="Button.VerticalContentAlignment" Value="Center"/>
+      <Setter Property="Button.Template">
+        <ControlTemplate TargetType="Button">
+          <Border Padding="3">
+            <ContentPresenter Content="Content Here"/>
+          </Border>
+        </ControlTemplate>
+      </Setter>
+    </Style>
+  </Application.Styles>
 </Application>

+ 1 - 0
src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs

@@ -15,6 +15,7 @@ namespace Perspex.Markup.Xaml.Context
         public PerspexObjectAssembler(IWiringContext wiringContext, ObjectAssemblerSettings objectAssemblerSettings = null)
         {
             var mapping = new DeferredLoaderMapping();
+            mapping.Map<ControlTemplate>(template => template.Content, new TemplateLoader());
             mapping.Map<DataTemplate>(template => template.Content, new TemplateLoader());
             mapping.Map<TreeDataTemplate>(template => template.Content, new TemplateLoader());
 

+ 2 - 0
src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs

@@ -115,11 +115,13 @@ namespace Perspex.Markup.Xaml.Context
             var contentProperties = new Collection<ContentPropertyDefinition>
             {
                 new ContentPropertyDefinition(typeof(ContentControl), "Content"),
+                new ContentPropertyDefinition(typeof(ControlTemplate), "Content"),
                 new ContentPropertyDefinition(typeof(DataTemplate), "Content"),
                 new ContentPropertyDefinition(typeof(Decorator), "Child"),
                 new ContentPropertyDefinition(typeof(ItemsControl), "Items"),
                 new ContentPropertyDefinition(typeof(GradientBrush), "GradientStops"),
                 new ContentPropertyDefinition(typeof(Panel), "Children"),
+                new ContentPropertyDefinition(typeof(Setter), "Value"),
                 new ContentPropertyDefinition(typeof(Style), "Setters"),
                 new ContentPropertyDefinition(typeof(TextBlock), "Text"),
                 new ContentPropertyDefinition(typeof(TextBox), "Text"),

+ 1 - 0
src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj

@@ -229,6 +229,7 @@
     <Compile Include="Parsers\SelectorParser.cs" />
     <Compile Include="Parsers\SelectorGrammar.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Templates\ControlTemplate.cs" />
     <Compile Include="Templates\TemplateLoader.cs" />
     <Compile Include="Templates\Template.cs" />
     <Compile Include="Templates\TemplateContent.cs" />

+ 21 - 0
src/Markup/Perspex.Markup.Xaml/Templates/ControlTemplate.cs

@@ -0,0 +1,21 @@
+// Copyright (c) The Perspex Project. All rights reserved.
+// Licensed under the MIT license. See licence.md file in the project root for full license information.
+
+using System;
+using Perspex.Controls;
+using Perspex.Controls.Templates;
+using Perspex.Styling;
+
+namespace Perspex.Markup.Xaml.Templates
+{
+    public class ControlTemplate : IControlTemplate
+    {
+        public Type TargetType { get; set; }
+        public TemplateContent Content { get; set; }
+
+        public IControl Build(ITemplatedControl control)
+        {
+            return Content.Load();
+        }
+    }
+}