Browse Source

save namespaces for later when using defered loader, otherwise they are lost

pull/916/head
Andrey Kunchev 10 years ago
parent
commit
6c72365766
  1. 19
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticExtension.cs
  2. 21
      src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs
  3. 10
      src/Markup/Avalonia.Markup.Xaml/Templates/TemplateLoader.cs

19
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticExtension.cs

@ -1,18 +1,12 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Portable.Xaml;
using Portable.Xaml.ComponentModel;
using Portable.Xaml.Markup;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Avalonia.Markup.Xaml.MarkupExtensions
{
#if !OMNIXAML
//TODO: check do we need something more than std Portable.xaml static??
public class StaticExtension : Portable.Xaml.Markup.StaticExtension
{
public StaticExtension()
@ -26,19 +20,6 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
public override object ProvideValue(IServiceProvider serviceProvider)
{
var tdc = (ITypeDescriptorContext)serviceProvider;
var ns = tdc.GetService<IXamlNamespaceResolver>();
if (!ns.GetNamespacePrefixes().Any())
{
//TODO: issue of portable.xaml ??? investigate
var cvp = tdc.GetService<IRootObjectProvider>();
var pvt = tdc.GetService<IProvideValueTarget>();
//ok we have a problem namespaces shouldn't be empty
var nslist = ns.GetNamespacePrefixes() as IList<NamespaceDeclaration>;
nslist.Add(new NamespaceDeclaration("https://github.com/avaloniaui", ""));
//this is just a hack
}
return base.ProvideValue(serviceProvider);
}
}

21
src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs

@ -1,9 +1,8 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Markup.Xaml.Context;
using System.Collections.Generic;
namespace Avalonia.Markup.Xaml.Templates
{
@ -12,21 +11,24 @@ namespace Avalonia.Markup.Xaml.Templates
public class TemplateContent
{
public TemplateContent()
{
}
public TemplateContent(XamlReader reader)
public TemplateContent(IEnumerable<NamespaceDeclaration> namespaces, XamlReader reader)
{
List = new XamlNodeList(reader.SchemaContext);
//we need to rpeserve all namespace and prefixes to writer
//otherwise they are lost. a bug in Portable.xaml or by design ??
foreach (var ns in namespaces)
{
List.Writer.WriteNamespace(ns);
}
XamlServices.Transform(reader, List.Writer);
}
public XamlNodeList List { get; set; }
public XamlNodeList List { get; }
public IControl Load()
{
//return (IControl)XamlServices.Load(List.GetReader());
return (IControl)AvaloniaXamlLoader.LoadFromReader(List.GetReader());
}
@ -37,6 +39,7 @@ namespace Avalonia.Markup.Xaml.Templates
}
#else
using Avalonia.Markup.Xaml.Context;
using OmniXaml;
using OmniXaml.ObjectAssembler;

10
src/Markup/Avalonia.Markup.Xaml/Templates/TemplateLoader.cs

@ -1,19 +1,21 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.Generic;
namespace Avalonia.Markup.Xaml.Templates
{
#if !OMNIXAML
using Portable.Xaml;
using Portable.Xaml.ComponentModel;
using System;
public class TemplateLoader : XamlDeferringLoader
{
public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
{
return new TemplateContent(xamlReader);
var tdc = (ITypeDescriptorContext)serviceProvider;
var ns = tdc.GetService<IXamlNamespaceResolver>();
return new TemplateContent(ns.GetNamespacePrefixes(), xamlReader);
}
public override XamlReader Save(object value, IServiceProvider serviceProvider)
@ -21,8 +23,10 @@ namespace Avalonia.Markup.Xaml.Templates
return ((TemplateContent)value).List.GetReader();
}
}
#else
using System.Collections.Generic;
using OmniXaml;
public class TemplateLoader : IDeferredLoader

Loading…
Cancel
Save