Browse Source

Now resolving xml namespaces via attributes

pull/143/head
Nikita Tsukanov 11 years ago
parent
commit
bec230211a
  1. 1
      Perspex.sln
  2. 112
      samples/XamlTestApplication/Views/MainWindow.xaml
  3. 1
      src/Gtk/Perspex.Gtk/GtkPlatform.cs
  4. 3
      src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj
  5. 53
      src/Markup/Perspex.Markup.Xaml/Context/PerspexWiringContext.cs
  6. 3
      src/Markup/Perspex.Markup.Xaml/Properties/AssemblyInfo.cs
  7. 21
      src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs
  8. 2
      src/Perspex.Base/Perspex.Base.csproj
  9. 14
      src/Perspex.Base/Platform/IPclPlatformWrapper.cs
  10. 6
      src/Perspex.Controls/Properties/AssemblyInfo.cs
  11. 2
      src/Perspex.Styling/Properties/AssemblyInfo.cs
  12. BIN
      src/Shared/PclPlatformWrapper.cs
  13. 3
      src/Windows/Perspex.Win32/Perspex.Win32.csproj
  14. 1
      src/Windows/Perspex.Win32/Win32Platform.cs

1
Perspex.sln

@ -79,6 +79,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{9B9E
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A689DEF5-D50F-4975-8B72-124C9EB54066}"
ProjectSection(SolutionItems) = preProject
src\Shared\PclPlatformWrapper.cs = src\Shared\PclPlatformWrapper.cs
src\Shared\SharedAssemblyInfo.cs = src\Shared\SharedAssemblyInfo.cs
EndProjectSection
EndProject

112
samples/XamlTestApplication/Views/MainWindow.xaml

@ -2,111 +2,9 @@
xmlns="https://github.com/perspex"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Perspex Test Application" Height="350" Width="525">
<Grid RowDefinitions="Auto,*">
<TabControl Grid.Row="1">
<TabItem Header="Buttons">
<StackPanel HorizontalAlignment="Center" Width="200" VerticalAlignment="Center">
<Button Content="Button" />
<Button Content="Button" Background="#119EDA" ToolTip.Tip="Goodbye Cruel World!" />
<Button Content="Default" IsDefault="True" />
<Button Content="Disabled" IsEnabled="False" />
<Button Content="Disabled" IsEnabled="False" Background="#119eda" />
<ToggleButton Content="Toggle" />
<ToggleButton Content="Toggle" IsEnabled="False" />
<CheckBox Content="Checkbox" />
<RadioButton Content="RadioButton 1" IsChecked="True" />
<RadioButton Content="RadioButton 2" />
</StackPanel>
</TabItem>
<TabItem Header="Text">
<StackPanel HorizontalAlignment="Center" Width="200" VerticalAlignment="Center">
<TextBlock
Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt."
TextWrapping="Wrap" TextAlignment="Center" />
<TextBlock Text="Italic text." TextWrapping="Wrap" TextAlignment="Left" FontStyle="Italic" />
<TextBlock TextWrapping="Wrap" TextAlignment="Right" FontWeight="Bold">Bold text.</TextBlock>
<TextBox Text="A non-wrapping text box. Lorem ipsum dolor sit amet." TextWrapping="NoWrap" />
<TextBox
Text="A wrapping text box. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt."
TextWrapping="Wrap" MaxHeight="100" AcceptsReturn="True" />
</StackPanel>
</TabItem>
<TabItem Header="Images">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<ScrollViewer Height="200" Width="200" HorizontalScrollBarVisibility="Visible">
<Image Source="github_icon.png" Height="500" Width="400" />
</ScrollViewer>
</StackPanel>
</TabItem>
<TabItem Header="Lists">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<ListBox>
<ListBoxItem>
<StackPanel>
<TextBlock Text="Item 1" FontSize="24" />
<TextBlock Text="Item 1 Value" />
</StackPanel>
</ListBoxItem>
<ListBoxItem>
<StackPanel>
<TextBlock Text="Item 2" FontSize="24" />
<TextBlock Text="Item 2 Value" />
</StackPanel>
</ListBoxItem>
</ListBox>
<DropDown VerticalAlignment="Center">
<StackPanel>
<TextBlock Text="Item 1" FontSize="24" />
<TextBlock Text="Item 1 Value" />
</StackPanel>
<StackPanel>
<TextBlock Text="Item 2" FontSize="24" />
<TextBlock Text="Item 2 Value" />
</StackPanel>
</DropDown>
</StackPanel>
</TabItem>
<TabItem Header="Layout">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel>
<Button HorizontalAlignment="Left" Content="Left Aligned" />
<Button HorizontalAlignment="Center" Content="Center Aligned" />
<Button HorizontalAlignment="Right" Content="Right Aligned" />
<Button HorizontalAlignment="Stretch" Content="Stretch" />
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button VerticalAlignment="Top" Content="Top Aligned" />
<Button VerticalAlignment="Center" Content="Center Aligned" />
<Button VerticalAlignment="Bottom" Content="Bottom Aligned" />
<Button VerticalAlignment="Stretch" Content="Stretch" />
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Animations">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Width="100" Height="100" Background="Crimson">
<TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Text="hello!"></TextBox>
</Border>
<Border Grid.Row="0" Grid.Column="1" Background="Coral" HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image Width="100" Height="100" Source="github_icon.png">
</Image>
</Border>
<Button Grid.Row="1" Grid.Column="1" Content="Animate" HorizontalAlignment="Center"></Button>
</Grid>
</TabItem>
</TabControl>
</Grid>
<Window.Styles>
<Style>
</Style>
</Window.Styles>
</Window>

1
src/Gtk/Perspex.Gtk/GtkPlatform.cs

@ -28,6 +28,7 @@ namespace Perspex.Gtk
public static void Initialize()
{
var locator = Locator.CurrentMutable;
locator.Register(() => new PclPlatformWrapper(), typeof(IPclPlatformWrapper));
locator.Register(() => new WindowImpl(), typeof(IWindowImpl));
locator.Register(() => new PopupImpl(), typeof(IPopupImpl));
locator.Register(() => new ClipboardImpl(), typeof(IClipboard));

3
src/Gtk/Perspex.Gtk/Perspex.Gtk.csproj

@ -58,6 +58,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Shared\PclPlatformWrapper.cs">
<Link>PclPlatformWrapper.cs</Link>
</Compile>
<Compile Include="AssetLoader.cs" />
<Compile Include="ClipboardImpl.cs" />
<Compile Include="CursorFactory.cs" />

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

@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using Glass;
using OmniXaml;
@ -16,6 +17,10 @@ using Perspex.Markup.Xaml.DataBinding;
using Perspex.Markup.Xaml.MarkupExtensions;
using Perspex.Media;
using Perspex.Media.Imaging;
using Perspex.Metadata;
using Perspex.Platform;
using Perspex.Styling;
using Splat;
namespace Perspex.Markup.Xaml.Context
{
@ -39,37 +44,27 @@ namespace Perspex.Markup.Xaml.Context
{
var xamlNamespaceRegistry = new XamlNamespaceRegistry();
var rootType = typeof(Control);
var bindingType = typeof(BindingExtension);
var templateType = typeof(XamlDataTemplate);
var definitionForRoot = XamlNamespace
.Map(PerspexNs)
.With(
new[]
{
Route.Assembly(rootType.GetTypeInfo().Assembly).WithNamespaces(
new[]
{
rootType.Namespace
}),
Route.Assembly(bindingType.GetTypeInfo().Assembly).WithNamespaces(
new[]
{
bindingType.Namespace,
}),
Route.Assembly(templateType.GetTypeInfo().Assembly).WithNamespaces(
new[]
{
templateType.Namespace,
})
});
foreach (var ns in new List<XamlNamespace> { definitionForRoot })
var forcedAssemblies = new[]
{
xamlNamespaceRegistry.AddNamespace(ns);
typeof (Control),
typeof(Style)
}.Select(t => t.GetTypeInfo().Assembly);
foreach (var nsa in
forcedAssemblies
.Concat(Locator.Current.GetService<IPclPlatformWrapper>().GetLoadedAssemblies())
.Distinct()
.SelectMany(asm
=> asm.GetCustomAttributes<XmlnsDefinitionAttribute>().Select(attr => new {asm, attr}))
.GroupBy(entry => entry.attr.XmlNamespace))
{
var def = XamlNamespace.Map(nsa.Key)
.With(nsa.GroupBy(x => x.asm).Select(
a => Route.Assembly(a.Key)
.WithNamespaces(a.Select(entry => entry.attr.ClrNamespace).ToList())
));
xamlNamespaceRegistry.AddNamespace(def);
}
xamlNamespaceRegistry.RegisterPrefix(new PrefixRegistration(string.Empty, PerspexNs));
return xamlNamespaceRegistry;

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

@ -2,5 +2,8 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection;
using Perspex.Metadata;
[assembly: AssemblyTitle("Perspex.Markup.Xaml")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.MarkupExtensions")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Markup.Xaml.Templates")]

21
src/Perspex.Base/Metadata/XmlnsDefinitionAttribute.cs

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Metadata
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class XmlnsDefinitionAttribute : Attribute
{
public string XmlNamespace { get; set; }
public string ClrNamespace { get; set; }
public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
{
XmlNamespace = xmlNamespace;
ClrNamespace = clrNamespace;
}
}
}

2
src/Perspex.Base/Perspex.Base.csproj

@ -46,8 +46,10 @@
<Compile Include="Diagnostics\PerspexObjectExtensions.cs" />
<Compile Include="IObservablePropertyBag.cs" />
<Compile Include="IPropertyBag.cs" />
<Compile Include="Metadata\XmlnsDefinitionAttribute.cs" />
<Compile Include="PerspexObjectExtensions.cs" />
<Compile Include="PerspexProperty`1.cs" />
<Compile Include="Platform\IPclPlatformWrapper.cs" />
<Compile Include="PriorityBindingEntry.cs" />
<Compile Include="Collections\IPerspexList.cs" />
<Compile Include="Collections\PerspexList.cs" />

14
src/Perspex.Base/Platform/IPclPlatformWrapper.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Perspex.Platform
{
public interface IPclPlatformWrapper
{
Assembly[] GetLoadedAssemblies();
}
}

6
src/Perspex.Controls/Properties/AssemblyInfo.cs

@ -3,6 +3,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using Perspex.Metadata;
[assembly: AssemblyTitle("Perspex.Controls")]
[assembly: InternalsVisibleTo("Perspex.Controls.UnitTests")]
[assembly: InternalsVisibleTo("Perspex.Controls.UnitTests")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Controls")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Controls.Primitives")]

2
src/Perspex.Styling/Properties/AssemblyInfo.cs

@ -2,5 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Reflection;
using Perspex.Metadata;
[assembly: AssemblyTitle("Perspex.Styling")]
[assembly: XmlnsDefinition("https://github.com/perspex", "Perspex.Styling")]

BIN
src/Shared/PclPlatformWrapper.cs

Binary file not shown.

3
src/Windows/Perspex.Win32/Perspex.Win32.csproj

@ -62,6 +62,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Shared\PclPlatformWrapper.cs">
<Link>PclPlatformWrapper.cs</Link>
</Compile>
<Compile Include="..\..\Shared\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>

1
src/Windows/Perspex.Win32/Win32Platform.cs

@ -40,6 +40,7 @@ namespace Perspex.Win32
private static void InitializeInternal()
{
var locator = Locator.CurrentMutable;
locator.Register(()=>new PclPlatformWrapper(), typeof(IPclPlatformWrapper));
locator.Register(() => new PopupImpl(), typeof(IPopupImpl));
locator.Register(() => new ClipboardImpl(), typeof(IClipboard));
locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice));

Loading…
Cancel
Save