Skip to content

Commit

Permalink
Design time converters should return TRUE for CanConvertFrom(typeof(s…
Browse files Browse the repository at this point in the history
…tring))
  • Loading branch information
etvorun committed Oct 27, 2022
1 parent dbfaf45 commit f792293
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;

namespace Microsoft.Maui.Controls.Design
{
public class GridLengthCollectionDesignTypeConverter : TypeConverter
{
// This tells XAML this converter can be used to process strings
// Without this the values won't show up as hints
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
=> sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);

public override bool IsValid(ITypeDescriptorContext context, object value)
{
if (value?.ToString() is string strValue)
Expand Down
4 changes: 4 additions & 0 deletions src/Controls/src/Core.Design/GridLengthDesignTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace Microsoft.Maui.Controls.Design
{
public class GridLengthDesignTypeConverter : TypeConverter
{
// This tells XAML this converter can be used to process strings
// Without this the values won't show up as hints
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
=> sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);

public override bool IsValid(ITypeDescriptorContext context, object value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ namespace Microsoft.Maui.Controls.Core.UnitTests
{
public class GridLengthCollectionDesignTypeConverterTests
{
[Fact]
public void GridLengthCollection_CanConvertFromString()
{
GridLengthCollectionDesignTypeConverter converter = new GridLengthCollectionDesignTypeConverter();
bool canConvert = converter.CanConvertFrom(typeof(string));
Assert.True(canConvert);
}

[Theory]
[InlineData("*,auto,123")]
[InlineData(" *, AUTO , 123 ")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ namespace Microsoft.Maui.Controls.Core.UnitTests
{
public class GridLengthDesignTypeConverterTests
{
[Fact]
public void GridLength_CanConvertFromString()
{
GridLengthDesignTypeConverter converter = new GridLengthDesignTypeConverter();
bool canConvert = converter.CanConvertFrom(typeof(string));
Assert.True(canConvert);
}

[Theory]
[InlineData("auto")]
[InlineData("Auto ")]
Expand Down

0 comments on commit f792293

Please sign in to comment.