Browse Source

tempalte binding in control template operational

pull/916/head
donandren 10 years ago
committed by Andrey Kunchev
parent
commit
55c6383a21
  1. 44
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlSchemaContext.cs
  2. 34
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs
  3. 6
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

44
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlSchemaContext.cs

@ -7,6 +7,7 @@ using Portable.Xaml;
using Portable.Xaml.ComponentModel; using Portable.Xaml.ComponentModel;
using am = Avalonia.Metadata; using am = Avalonia.Metadata;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Markup.Xaml.Data;
namespace Avalonia.Markup.Xaml.PortableXaml namespace Avalonia.Markup.Xaml.PortableXaml
{ {
@ -54,17 +55,19 @@ namespace Avalonia.Markup.Xaml.PortableXaml
} }
// MarkupExtension type could omit "Extension" part in XML name. // MarkupExtension type could omit "Extension" part in XML name.
Type type = _avaloniaTypeProvider.FindType(xmlNamespace, xmlLocalName, genArgs) Type type = _avaloniaTypeProvider.FindType(xmlNamespace,
?? _avaloniaTypeProvider.FindType(xmlNamespace, xmlLocalName,
xmlLocalName + "Extension", genArgs) ??
genArgs); _avaloniaTypeProvider.FindType(xmlNamespace,
xmlLocalName + "Extension",
genArgs);
if (type == null) if (type == null)
{ {
//let's try the simple types //let's try the simple types
//in Portable xaml xmlns:sys='clr-namespace:System;assembly=mscorlib' //in Portable xaml like xmlns:sys='clr-namespace:System;assembly=mscorlib'
//and sys:Double is not resolved //and sys:Double is not resolved properly
return ResolveSimpleTypeName(xmlNamespace, xmlLocalName); return ResolveSimpleTypeName(xmlNamespace, xmlLocalName);
} }
@ -91,6 +94,9 @@ namespace Avalonia.Markup.Xaml.PortableXaml
private static Dictionary<Tuple<string, string>, XamlType> _simpleXamlTypes; private static Dictionary<Tuple<string, string>, XamlType> _simpleXamlTypes;
//in Portable xaml like xmlns:sys='clr-namespace:System;assembly=mscorlib'
//and sys:Double is not resolved properly
[Obsolete("TODO: remove once it's fixed in Portable.xaml")]
private static XamlType ResolveSimpleTypeName(string xmlNamespace, string xmlLocalName) private static XamlType ResolveSimpleTypeName(string xmlNamespace, string xmlLocalName)
{ {
if (_simpleXamlTypes == null) if (_simpleXamlTypes == null)
@ -125,13 +131,33 @@ namespace Avalonia.Markup.Xaml.PortableXaml
public override XamlType GetXamlType(Type type) public override XamlType GetXamlType(Type type)
{ {
XamlType result = null;
if (_cachedTypes.TryGetValue(type, out result))
{
return result;
}
_cachedTypes[type] = result = GetAvaloniaXamlType(type) ?? base.GetXamlType(type);
return result;
}
private XamlType GetAvaloniaXamlType(Type type)
{
if (type == typeof(Binding))
{
return new BindingXamlType(type, this);
}
//TODO: do we need it ???
//if (type.FullName.StartsWith("Avalonia.")) //if (type.FullName.StartsWith("Avalonia."))
//{ //{
// return new AvaloniaXamlType(type, this); // return new AvaloniaXamlType(type, this);
//} //}
return base.GetXamlType(type);
}
return null;
}
protected override XamlMember GetAttachableProperty(string attachablePropertyName, MethodInfo getter, MethodInfo setter) protected override XamlMember GetAttachableProperty(string attachablePropertyName, MethodInfo getter, MethodInfo setter)
{ {
@ -164,5 +190,7 @@ namespace Avalonia.Markup.Xaml.PortableXaml
return base.GetProperty(pi); return base.GetProperty(pi);
} }
private Dictionary<Type, XamlType> _cachedTypes = new Dictionary<Type, XamlType>();
} }
} }

34
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs

@ -3,23 +3,31 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Avalonia.Data; using Avalonia.Data;
using Portable.Xaml; using Portable.Xaml;
using Portable.Xaml.Markup;
using Portable.Xaml.Schema; using Portable.Xaml.Schema;
namespace Avalonia.Markup.Xaml.PortableXaml namespace Avalonia.Markup.Xaml.PortableXaml
{ {
//public class AvaloniaXamlType : XamlType public class AvaloniaXamlType : XamlType
//{ {
// public AvaloniaXamlType(Type underlyingType, XamlSchemaContext schemaContext) : public AvaloniaXamlType(Type underlyingType, XamlSchemaContext schemaContext) :
// base(underlyingType, schemaContext) base(underlyingType, schemaContext)
// { {
// } }
}
// protected override XamlMember LookupMember(string name, bool skipReadOnlyCheck)
// { public class BindingXamlType : AvaloniaXamlType
// return base.LookupMember(name, skipReadOnlyCheck); {
// } public BindingXamlType(Type underlyingType, XamlSchemaContext schemaContext) :
//} base(underlyingType, schemaContext)
{
}
public override bool CanAssignTo(XamlType xamlType)
{
return true;
}
}
public class AvaloniaPropertyXamlMember : XamlMember public class AvaloniaPropertyXamlMember : XamlMember
{ {

6
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

@ -247,12 +247,8 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
<Setter Property='Template'> <Setter Property='Template'>
<ControlTemplate> <ControlTemplate>
<ContentPresenter Name='PART_ContentPresenter' <ContentPresenter Name='PART_ContentPresenter'
Background='{TemplateBinding Background}'
BorderBrush='{TemplateBinding BorderBrush}'
BorderThickness='{TemplateBinding BorderThickness}'
Content='{TemplateBinding Content}' Content='{TemplateBinding Content}'
ContentTemplate='{TemplateBinding ContentTemplate}' ContentTemplate='{TemplateBinding ContentTemplate}' />
Padding='{TemplateBinding Padding}' />
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> "; </Style> ";

Loading…
Cancel
Save