7 changed files with 125 additions and 4 deletions
@ -0,0 +1,27 @@ |
|||
// 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.Globalization; |
|||
using Xunit; |
|||
|
|||
namespace Perspex.SceneGraph.UnitTests |
|||
{ |
|||
public class RelativePointTests |
|||
{ |
|||
[Fact] |
|||
public void Parse_Should_Accept_Absolute_Value() |
|||
{ |
|||
var result = RelativePoint.Parse("4,5", CultureInfo.InvariantCulture); |
|||
|
|||
Assert.Equal(new RelativePoint(4, 5, RelativeUnit.Absolute), result); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Parse_Should_Accept_Relative_Value() |
|||
{ |
|||
var result = RelativePoint.Parse("25%, 50%", CultureInfo.InvariantCulture); |
|||
|
|||
Assert.Equal(new RelativePoint(0.25, 0.5, RelativeUnit.Relative), result); |
|||
} |
|||
} |
|||
} |
|||
@ -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 RelativePointTypeConverter : 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 RelativePoint.Parse((string)value, culture); |
|||
} |
|||
|
|||
public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue