Browse Source

Updated OmniXAML.

pull/448/head
Steven Kirk 10 years ago
parent
commit
2234c6dba4
  1. 5
      src/Markup/Perspex.Markup.Xaml/Context/PerspexMemberValuePlugin.cs
  2. 13
      src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs
  3. 5
      src/Markup/Perspex.Markup.Xaml/Context/PerspexParserFactory.cs
  4. 15
      src/Markup/Perspex.Markup.Xaml/Context/PropertyAccessor.cs
  5. 8
      src/Markup/Perspex.Markup.Xaml/Converters/BitmapTypeConverter.cs
  6. 8
      src/Markup/Perspex.Markup.Xaml/Converters/BrushTypeConverter.cs
  7. 8
      src/Markup/Perspex.Markup.Xaml/Converters/ClassesTypeConverter.cs
  8. 8
      src/Markup/Perspex.Markup.Xaml/Converters/ColorTypeConverter.cs
  9. 8
      src/Markup/Perspex.Markup.Xaml/Converters/ColumnDefinitionsTypeConverter.cs
  10. 8
      src/Markup/Perspex.Markup.Xaml/Converters/CursorTypeConverter.cs
  11. 8
      src/Markup/Perspex.Markup.Xaml/Converters/GeometryTypeConverter.cs
  12. 8
      src/Markup/Perspex.Markup.Xaml/Converters/GridLengthTypeConverter.cs
  13. 8
      src/Markup/Perspex.Markup.Xaml/Converters/KeyGestureConverter.cs
  14. 8
      src/Markup/Perspex.Markup.Xaml/Converters/MemberSelectorTypeConverter.cs
  15. 8
      src/Markup/Perspex.Markup.Xaml/Converters/PerspexListTypeConverter.cs
  16. 8
      src/Markup/Perspex.Markup.Xaml/Converters/PerspexPropertyTypeConverter.cs
  17. 8
      src/Markup/Perspex.Markup.Xaml/Converters/PointTypeConverter.cs
  18. 8
      src/Markup/Perspex.Markup.Xaml/Converters/PointsListTypeConverter.cs
  19. 8
      src/Markup/Perspex.Markup.Xaml/Converters/RelativePointTypeConverter.cs
  20. 8
      src/Markup/Perspex.Markup.Xaml/Converters/RelativeRectTypeConverter.cs
  21. 8
      src/Markup/Perspex.Markup.Xaml/Converters/RowDefinitionsTypeConverter.cs
  22. 8
      src/Markup/Perspex.Markup.Xaml/Converters/SelectorTypeConverter.cs
  23. 8
      src/Markup/Perspex.Markup.Xaml/Converters/ThicknessTypeConverter.cs
  24. 8
      src/Markup/Perspex.Markup.Xaml/Converters/TimeSpanTypeConverter.cs
  25. 8
      src/Markup/Perspex.Markup.Xaml/Converters/UriTypeConverter.cs
  26. 2
      src/Markup/Perspex.Markup.Xaml/OmniXAML
  27. 7
      src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj
  28. 5
      src/Markup/Perspex.Markup.Xaml/Templates/TemplateContent.cs
  29. 4
      tests/Perspex.Markup.Xaml.UnitTests/Converters/PerspexPropertyConverterTest.cs

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

@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using OmniXaml.TypeConversion;
using OmniXaml.Typing;
namespace Perspex.Markup.Xaml.Context
@ -16,9 +17,9 @@ namespace Perspex.Markup.Xaml.Context
_xamlMember = xamlMember;
}
public override void SetValue(object instance, object value)
public override void SetValue(object instance, object value, IValueContext valueContext)
{
PropertyAccessor.SetValue(instance, _xamlMember, value);
PropertyAccessor.SetValue(instance, _xamlMember, value, valueContext);
}
}
}

13
src/Markup/Perspex.Markup.Xaml/Context/PerspexObjectAssembler.cs

@ -4,19 +4,21 @@
using System;
using OmniXaml;
using OmniXaml.ObjectAssembler;
using Perspex.Controls;
using OmniXaml.ObjectAssembler.Commands;
using OmniXaml.TypeConversion;
using Perspex.Markup.Xaml.Templates;
namespace Perspex.Markup.Xaml.Context
{
using OmniXaml.ObjectAssembler.Commands;
public class PerspexObjectAssembler : IObjectAssembler
{
private readonly TemplateHostingObjectAssembler objectAssembler;
private readonly ObjectAssembler assembler;
public PerspexObjectAssembler(IRuntimeTypeSource runtimeTypeSource, Settings objectAssemblerSettings = null)
public PerspexObjectAssembler(
IRuntimeTypeSource typeSource,
ITopDownValueContext topDownValueContext,
Settings settings = null)
{
var mapping = new DeferredLoaderMapping();
mapping.Map<ControlTemplate>(x => x.Content, new TemplateLoader());
@ -25,7 +27,8 @@ namespace Perspex.Markup.Xaml.Context
mapping.Map<TreeDataTemplate>(x => x.Content, new TemplateLoader());
mapping.Map<ItemsPanelTemplate>(x => x.Content, new TemplateLoader());
assembler = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), objectAssemblerSettings);
var valueContext = new ValueContext(typeSource, topDownValueContext);
assembler = new ObjectAssembler(typeSource, valueContext, settings);
objectAssembler = new TemplateHostingObjectAssembler(assembler, mapping);
}

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

@ -26,7 +26,10 @@ namespace Perspex.Markup.Xaml.Context
{
var xamlInstructionParser = new OrderAwareInstructionParser(new InstructionParser(runtimeTypeSource));
IObjectAssembler objectAssembler = new PerspexObjectAssembler(runtimeTypeSource, settings);
IObjectAssembler objectAssembler = new PerspexObjectAssembler(
runtimeTypeSource,
new TopDownValueContext(),
settings);
var phaseParserKit = new PhaseParserKit(
new ProtoInstructionParser(runtimeTypeSource),
xamlInstructionParser,

15
src/Markup/Perspex.Markup.Xaml/Context/PropertyAccessor.cs

@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using OmniXaml.ObjectAssembler;
using OmniXaml.TypeConversion;
using OmniXaml.Typing;
using Perspex.Data;
using Perspex.Styling;
@ -14,7 +15,11 @@ namespace Perspex.Markup.Xaml.Context
{
internal static class PropertyAccessor
{
public static void SetValue(object instance, MutableMember member, object value)
public static void SetValue(
object instance,
MutableMember member,
object value,
IValueContext context)
{
var perspexProperty = FindPerspexProperty(instance, member);
@ -31,9 +36,13 @@ namespace Perspex.Markup.Xaml.Context
// TODO: Make this more generic somehow.
var setter = (Setter)instance;
var targetType = setter.Property.PropertyType;
var valuePipeline = new ValuePipeline(member.TypeRepository, null);
var xamlType = member.TypeRepository.GetByType(targetType);
SetClrProperty(instance, member, valuePipeline.ConvertValueIfNecessary(value, xamlType));
var convertedValue = default(object);
if (CommonValueConversion.TryConvert(value, xamlType, context, out convertedValue))
{
SetClrProperty(instance, member, convertedValue);
}
}
else
{

8
src/Markup/Perspex.Markup.Xaml/Converters/BitmapTypeConverter.cs

@ -11,17 +11,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class BitmapTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var uri = new Uri((string)value, UriKind.RelativeOrAbsolute);
var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file";
@ -36,7 +36,7 @@ namespace Perspex.Markup.Xaml.Converters
}
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/BrushTypeConverter.cs

@ -10,22 +10,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class BrushTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return Brush.Parse((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/ClassesTypeConverter.cs

@ -11,22 +11,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class ClassesTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return new Classes(((string)value).Split(' '));
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/ColorTypeConverter.cs

@ -10,22 +10,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class ColorTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return Color.Parse((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/ColumnDefinitionsTypeConverter.cs

@ -10,22 +10,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class ColumnDefinitionsTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return new ColumnDefinitions((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/CursorTypeConverter.cs

@ -12,23 +12,23 @@ namespace Perspex.Markup.Xaml.Converters
{
public class CursorTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var cursor = (StandardCursorType)Enum.Parse(typeof (StandardCursorType), ((string) value).Trim(), true);
return new Cursor(cursor);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/GeometryTypeConverter.cs

@ -7,22 +7,22 @@ namespace Perspex.Markup.Xaml.Converters
public class GeometryTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return StreamGeometry.Parse((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/GridLengthTypeConverter.cs

@ -10,22 +10,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class GridLengthTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return GridLength.Parse((string)value, culture);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/KeyGestureConverter.cs

@ -7,22 +7,22 @@ namespace Perspex.Markup.Xaml.Converters
{
class KeyGestureConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return KeyGesture.Parse((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/MemberSelectorTypeConverter.cs

@ -10,17 +10,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class MemberSelectorTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return new MemberSelector
{
@ -28,7 +28,7 @@ namespace Perspex.Markup.Xaml.Converters
};
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/PerspexListTypeConverter.cs

@ -12,17 +12,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class PerspexListTypeConverter<T> : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var result = new PerspexList<T>();
var values = ((string)value).Split(',');
@ -44,7 +44,7 @@ namespace Perspex.Markup.Xaml.Converters
return result;
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/PerspexPropertyTypeConverter.cs

@ -12,17 +12,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class PerspexPropertyTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var s = (string)value;
@ -68,7 +68,7 @@ namespace Perspex.Markup.Xaml.Converters
return property;
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/PointTypeConverter.cs

@ -9,22 +9,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class PointTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return Point.Parse((string)value, culture);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/PointsListTypeConverter.cs

@ -10,17 +10,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class PointsListTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
string strValue = (string)value;
string[] pointStrs = strValue.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
@ -32,7 +32,7 @@ namespace Perspex.Markup.Xaml.Converters
return result;
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/RelativePointTypeConverter.cs

@ -9,22 +9,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class RelativePointTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return RelativePoint.Parse((string)value, culture);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/RelativeRectTypeConverter.cs

@ -9,22 +9,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class RelativeRectTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return RelativeRect.Parse((string)value, culture);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/RowDefinitionsTypeConverter.cs

@ -10,22 +10,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class RowDefinitionsTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return new RowDefinitions((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/SelectorTypeConverter.cs

@ -10,23 +10,23 @@ namespace Perspex.Markup.Xaml.Converters
{
public class SelectorTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var parser = new SelectorParser((t, ns) => context.TypeRepository.GetByPrefix(ns ?? "", t).UnderlyingType);
return parser.Parse((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/ThicknessTypeConverter.cs

@ -9,22 +9,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class ThicknessTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return Thickness.Parse((string)value, culture);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

8
src/Markup/Perspex.Markup.Xaml/Converters/TimeSpanTypeConverter.cs

@ -10,17 +10,17 @@ namespace Perspex.Markup.Xaml.Converters
{
public class TimeSpanTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
var valueStr = (string)value;
if (!valueStr.Contains(":"))
@ -33,7 +33,7 @@ namespace Perspex.Markup.Xaml.Converters
return TimeSpan.Parse(valueStr);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

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

@ -9,22 +9,22 @@ namespace Perspex.Markup.Xaml.Converters
{
public class UriTypeConverter : ITypeConverter
{
public bool CanConvertFrom(ITypeConverterContext context, Type sourceType)
public bool CanConvertFrom(IValueContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public bool CanConvertTo(ITypeConverterContext context, Type destinationType)
public bool CanConvertTo(IValueContext context, Type destinationType)
{
return false;
}
public object ConvertFrom(ITypeConverterContext context, CultureInfo culture, object value)
public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
{
return new Uri((string)value);
}
public object ConvertTo(ITypeConverterContext context, CultureInfo culture, object value, Type destinationType)
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType)
{
throw new NotImplementedException();
}

2
src/Markup/Perspex.Markup.Xaml/OmniXAML

@ -1 +1 @@
Subproject commit 5209a3f26268fc55b82fbf8a05fbedce160e230f
Subproject commit 307361d65a187d404da1d4e15a553d918c3ed79c

7
src/Markup/Perspex.Markup.Xaml/Perspex.Markup.Xaml.csproj

@ -166,9 +166,9 @@
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\PreviousLevelWrapper.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\Settings.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\StateCommuter.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\StoredInstance.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\TopDownValueContext.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\TypeOperations.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\ValuePipeline.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\ValueProcessingMode.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ObjectAssembler\XamlSetValueEventArgs.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\ParseException.cs" />
@ -212,17 +212,18 @@
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\BuiltInConverters\StringTypeConverter.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\BuiltInConverters\TypeTypeConverter.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\ITypeConverter.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\ITypeConverterContext.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\ITypeConverterProvider.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\IValueContext.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\TypeConverterAttribute.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\TypeConverterContext.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\TypeConverterProvider.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeConversion\ValueContext.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeFactory.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeFactoryMixin.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeFeatureProvider.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\TypeNotFoundException.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\AttachableMember.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\ClrNamespace.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\CommonValueConversion.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\CoreTypes.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\DependencyRegistration.cs" />
<Compile Include="OmniXAML\Source\OmniXaml\Typing\DependencyRegistrations.cs" />

5
src/Markup/Perspex.Markup.Xaml/Templates/TemplateContent.cs

@ -3,6 +3,7 @@
using System.Collections.Generic;
using OmniXaml;
using OmniXaml.ObjectAssembler;
using Perspex.Controls;
using Perspex.Markup.Xaml.Context;
@ -21,7 +22,9 @@ namespace Perspex.Markup.Xaml.Templates
public Control Load()
{
var assembler = new PerspexObjectAssembler(runtimeTypeSource);
var assembler = new PerspexObjectAssembler(
runtimeTypeSource,
new TopDownValueContext());
foreach (var xamlNode in nodes)
{

4
tests/Perspex.Markup.Xaml.UnitTests/Converters/PerspexPropertyConverterTest.cs

@ -56,9 +56,9 @@ namespace Perspex.Markup.Xaml.UnitTests.Converters
Assert.Equal(AttachedOwner.AttachedProperty, result);
}
private ITypeConverterContext CreateContext(Style style = null)
private IValueContext CreateContext(Style style = null)
{
var context = new Mock<ITypeConverterContext>();
var context = new Mock<IValueContext>();
var topDownValueContext = new Mock<ITopDownValueContext>();
var typeRepository = new Mock<ITypeRepository>();
var featureProvider = new Mock<ITypeFeatureProvider>();

Loading…
Cancel
Save