Browse Source

Put button style into its own file.

And add StyleInclude class to import it. Unfortunately doesn't work yet
due to bug in OmniXAML: https://github.com/SuperJMN/OmniXAML/issues/48
pull/297/head
Steven Kirk 11 years ago
parent
commit
a18795b160
  1. 33
      samples/XamlTestApplicationPcl/Button.paml
  2. 32
      samples/XamlTestApplicationPcl/XamlTestApp.paml
  3. 3
      samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj
  4. 5
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  5. 32
      src/Markup/Perspex.Markup.Xaml/Converters/UriTypeConverter.cs
  6. 2
      src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj
  7. 2
      src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs
  8. 1
      src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs
  9. 39
      src/Markup/Perspex.Markup.Xaml/Styling/StyleInclude.cs

33
samples/XamlTestApplicationPcl/Button.paml

@ -0,0 +1,33 @@
<Styles xmlns="https://github.com/perspex">
<Style Selector="Button">
<Setter Property="Background" Value="#ffaaaaaa"/>
<Setter Property="BorderBrush" Value="#ffaaaaaa"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<ControlTemplate TargetType="Button">
<Border Name="border"
Padding="3"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Content="{TemplateBinding Content}"
TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="Button:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="#ff888888"/>
</Style>
<Style Selector="Button:pressed /template/ Border#border">
<Setter Property="Background" Value="#ff888888"/>
</Style>
<Style Selector="Button:disabled">
<Setter Property="Opacity" Value="0.5"/>
</Style>
</Styles>

32
samples/XamlTestApplicationPcl/XamlTestApp.paml

@ -2,36 +2,6 @@
xmlns="https://github.com/perspex"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Styles>
<Style Selector="Button">
<Setter Property="Background" Value="#ffaaaaaa"/>
<Setter Property="BorderBrush" Value="#ffaaaaaa"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<ControlTemplate TargetType="Button">
<Border Name="border"
Padding="3"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Content="{TemplateBinding Content}"
TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="Button:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="#ff888888"/>
</Style>
<Style Selector="Button:pressed /template/ Border#border">
<Setter Property="Background" Value="#ff888888"/>
</Style>
<Style Selector="Button:disabled">
<Setter Property="Opacity" Value="0.5"/>
</Style>
<StyleInclude Source="resource://application/XamlTestApplicationPcl/XamlTestApplication.Button.paml"/>
</Application.Styles>
</Application>

3
samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj

@ -121,6 +121,9 @@
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="packages.config" />
<EmbeddedResource Include="Button.paml">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

5
src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs

@ -95,14 +95,15 @@ namespace Perspex.Markup.Xaml.Context
new TypeConverterRegistration(typeof(Classes), new ClassesTypeConverter()),
new TypeConverterRegistration(typeof(ColumnDefinitions), new ColumnDefinitionsTypeConverter()),
new TypeConverterRegistration(typeof(GridLength), new GridLengthTypeConverter()),
new TypeConverterRegistration(typeof(KeyGesture), new KeyGestureConverter()),
new TypeConverterRegistration(typeof(Point), new PointTypeConverter()),
new TypeConverterRegistration(typeof(PerspexProperty), new PerspexPropertyTypeConverter()),
new TypeConverterRegistration(typeof(RelativePoint), new RelativePointTypeConverter()),
new TypeConverterRegistration(typeof(RowDefinitions), new RowDefinitionsTypeConverter()),
new TypeConverterRegistration(typeof(Thickness), new ThicknessTypeConverter()),
new TypeConverterRegistration(typeof(Selector), new SelectorTypeConverter()),
new TypeConverterRegistration(typeof(Thickness), new ThicknessTypeConverter()),
new TypeConverterRegistration(typeof(TimeSpan), new TimeSpanTypeConverter()),
new TypeConverterRegistration(typeof(KeyGesture), new KeyGestureConverter())
new TypeConverterRegistration(typeof(Uri), new UriTypeConverter()),
};
typeConverterProvider.AddAll(converters);

32
src/Markup/Perspex.Markup.Xaml/Converters/UriTypeConverter.cs

@ -0,0 +1,32 @@
// 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 System.Globalization;
using OmniXaml.TypeConversion;
namespace Perspex.Markup.Xaml.Converters
{
public class UriTypeConverter : ITypeConverter
{
public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
{
return new Uri((string)value);
}
public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}
}
}

2
src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj

@ -51,6 +51,7 @@
<Compile Include="Converters\ClassesTypeConverter.cs" />
<Compile Include="Converters\RowDefinitionsTypeConverter.cs" />
<Compile Include="Converters\ColumnDefinitionsTypeConverter.cs" />
<Compile Include="Converters\UriTypeConverter.cs" />
<Compile Include="Converters\ThicknessTypeConverter.cs" />
<Compile Include="Converters\PerspexPropertyTypeConverter.cs" />
<Compile Include="Converters\SelectorTypeConverter.cs" />
@ -231,6 +232,7 @@
<Compile Include="Parsers\SelectorParser.cs" />
<Compile Include="Parsers\SelectorGrammar.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Styling\StyleInclude.cs" />
<Compile Include="Templates\ControlTemplate.cs" />
<Compile Include="Templates\TemplateLoader.cs" />
<Compile Include="Templates\Template.cs" />

2
src/Markup/Perspex.Markup.Xaml/PerspexXamlLoader.cs

@ -108,7 +108,7 @@ namespace Perspex.Markup.Xaml
{
var asm = type.GetTypeInfo().Assembly.GetName().Name;
var typeName = type.FullName;
yield return new Uri("resource://application/" + asm + "/" + typeName+".xaml");
yield return new Uri("resource://application/" + asm + "/" + typeName + ".xaml");
yield return new Uri("resource://application/" + asm + "/" + typeName + ".paml");
}

1
src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs

@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("Perspex.Markup.Xaml")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.MarkupExtensions")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.Styling")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.Templates")]
[assembly: InternalsVisibleTo("Perspex.Markup.Xaml.UnitTests")]

39
src/Markup/Perspex.Markup.Xaml/Styling/StyleInclude.cs

@ -0,0 +1,39 @@
// 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.Styling;
namespace Perspex.Markup.Xaml.Styling
{
/// <summary>
/// Includes a style from a URL.
/// </summary>
public class StyleInclude : IStyle
{
/// <summary>
/// Gets or sets the source URL.
/// </summary>
public Uri Source { get; set; }
/// <summary>
/// Gets the loaded style.
/// </summary>
public IStyle Loaded { get; private set; }
/// <inheritdoc/>
public void Attach(IStyleable control, IStyleHost container)
{
if (Source != null)
{
if (Loaded == null)
{
var loader = new PerspexXamlLoader();
Loaded = (IStyle)loader.Load(Source);
}
Loaded.Attach(control, container);
}
}
}
}
Loading…
Cancel
Save