Skip to content

Commit af09229

Browse files
[X|C] only use a single GridLengthTypeConverter (#29376)
* [X|C] only use a single GridLengthTypeConverter - fixes #29334 * fix tests
1 parent 26fe44f commit af09229

File tree

20 files changed

+206
-29
lines changed

20 files changed

+206
-29
lines changed

src/Controls/Foldable/src/TwoPaneView.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Maui.Devices;
66
using Microsoft.Maui.Foldable;
77
using Microsoft.Maui.Graphics;
8+
using Microsoft.Maui.Converters;
89

910
namespace Microsoft.Maui.Controls.Foldable
1011
{
@@ -152,7 +153,7 @@ public double MinWideModeWidth
152153
/// <summary>
153154
/// Gets the calculated width (in wide mode) or height (in tall mode) of pane 1, or sets the GridLength value of pane 1.
154155
/// </summary>
155-
[System.ComponentModel.TypeConverter(typeof(GridLengthTypeConverter))]
156+
[System.ComponentModel.TypeConverter(typeof(Converters.GridLengthTypeConverter))]
156157
public GridLength Pane1Length
157158
{
158159
get { return (GridLength)GetValue(Pane1LengthProperty); }
@@ -162,7 +163,7 @@ public GridLength Pane1Length
162163
/// <summary>
163164
/// Gets the calculated width (in wide mode) or height (in tall mode) of pane 2, or sets the GridLength value of pane 2.
164165
/// </summary>
165-
[System.ComponentModel.TypeConverter(typeof(GridLengthTypeConverter))]
166+
[System.ComponentModel.TypeConverter(typeof(Converters.GridLengthTypeConverter))]
166167
public GridLength Pane2Length
167168
{
168169
get { return (GridLength)GetValue(Pane2LengthProperty); }

src/Controls/src/Build.Tasks/XamlCache.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public ICollection<string> GetResourceNamesInUse(VariableDefinition variableDefi
7474
{ module.ImportReference(this, ("Microsoft.Maui", "Microsoft.Maui.Converters", "FlexAlignSelfTypeConverter")), typeof(EnumTypeConverter<Layouts.FlexAlignSelf>) },
7575
{ module.ImportReference(this, ("Microsoft.Maui", "Microsoft.Maui.Converters", "FlexWrapTypeConverter")), typeof(EnumTypeConverter<Layouts.FlexWrap>) },
7676
{ module.ImportReference(this, ("Microsoft.Maui", "Microsoft.Maui.Converters", "FlexBasisTypeConverter")), typeof(FlexBasisTypeConverter) },
77+
{ module.ImportReference(this, ("Microsoft.Maui", "Microsoft.Maui.Converters", "GridLengthTypeConverter")), typeof(Microsoft.Maui.Controls.XamlC.GridLengthTypeConverter) },
78+
7779
};
7880

7981
// State used by SetPropertiesVisitor

src/Controls/src/Core/ColumnDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ColumnDefinition(GridLength width)
1919
=> SetValue(WidthProperty, width);
2020

2121
/// <summary>Gets or sets the width of the column.</summary>
22-
[System.ComponentModel.TypeConverter(typeof(GridLengthTypeConverter))]
22+
[System.ComponentModel.TypeConverter(typeof(Converters.GridLengthTypeConverter))]
2323
public GridLength Width
2424
{
2525
get { return (GridLength)GetValue(WidthProperty); }

src/Controls/src/Core/ColumnDefinitionCollectionTypeConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
3333
var definitions = new List<ColumnDefinition>(count);
3434
foreach (var range in unsplit.Split(','))
3535
{
36-
var length = GridLengthTypeConverter.ParseStringToGridLength(unsplit[range]);
36+
var length = Converters.GridLengthTypeConverter.ParseStringToGridLength(unsplit[range]);
3737
definitions.Add(new ColumnDefinition(length));
3838
}
3939
#else
@@ -42,7 +42,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
4242
var definitions = new List<ColumnDefinition>(count);
4343
foreach (var lengthStr in lengths)
4444
{
45-
var length = GridLengthTypeConverter.ParseStringToGridLength(lengthStr);
45+
var length = Converters.GridLengthTypeConverter.ParseStringToGridLength(lengthStr);
4646
definitions.Add(new ColumnDefinition(length));
4747
}
4848
#endif
@@ -62,15 +62,15 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
6262
if (count == 0)
6363
return string.Empty;
6464
if (count == 1)
65-
return GridLengthTypeConverter.ConvertToString(definitions[0].Width);
65+
return Converters.GridLengthTypeConverter.ConvertToString(definitions[0].Width);
6666

6767
// for multiple items
6868
var pool = ArrayPool<string>.Shared;
6969
var rentedArray = pool.Rent(definitions.Count);
7070
for (var i = 0; i < definitions.Count; i++)
7171
{
7272
var definition = definitions[i];
73-
rentedArray[i] = GridLengthTypeConverter.ConvertToString(definition.Width);
73+
rentedArray[i] = Converters.GridLengthTypeConverter.ConvertToString(definition.Width);
7474
}
7575
var result = string.Join(", ", rentedArray, 0, definitions.Count);
7676
pool.Return(rentedArray);

src/Controls/src/Core/GridLengthTypeConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Microsoft.Maui.Controls
77
{
88
[ProvideCompiled("Microsoft.Maui.Controls.XamlC.GridLengthTypeConverter")]
9+
[Obsolete("Microsoft.Maui.Controls.GridLengthTypeConverter is obsolete. Use Microsoft.Maui.Converters.GridLengthConverter instead.")]
910
public class GridLengthTypeConverter : TypeConverter
1011
{
1112
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)

src/Controls/src/Core/RowDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public RowDefinition(GridLength height)
2121
}
2222

2323
/// <include file="../../docs/Microsoft.Maui.Controls/RowDefinition.xml" path="//Member[@MemberName='Height']/Docs/*" />
24-
[System.ComponentModel.TypeConverter(typeof(GridLengthTypeConverter))]
24+
[System.ComponentModel.TypeConverter(typeof(Converters.GridLengthTypeConverter))]
2525
public GridLength Height
2626
{
2727
get { return (GridLength)GetValue(HeightProperty); }

src/Controls/src/Core/RowDefinitionCollectionTypeConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
3333
var definitions = new List<RowDefinition>(count);
3434
foreach (var range in unsplit.Split(','))
3535
{
36-
var length = GridLengthTypeConverter.ParseStringToGridLength(unsplit[range]);
36+
var length = Converters.GridLengthTypeConverter.ParseStringToGridLength(unsplit[range]);
3737
definitions.Add(new RowDefinition(length));
3838
}
3939
#else
@@ -42,7 +42,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
4242
var definitions = new List<RowDefinition>(count);
4343
foreach (var lengthStr in lengths)
4444
{
45-
var length = GridLengthTypeConverter.ParseStringToGridLength(lengthStr);
45+
var length = Converters.GridLengthTypeConverter.ParseStringToGridLength(lengthStr);
4646
definitions.Add(new RowDefinition(length));
4747
}
4848
#endif
@@ -61,15 +61,15 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
6161
if (count == 0)
6262
return string.Empty;
6363
if (count == 1)
64-
return GridLengthTypeConverter.ConvertToString(definitions[0].Height);
64+
return Converters.GridLengthTypeConverter.ConvertToString(definitions[0].Height);
6565

6666
// for multiple items
6767
var pool = ArrayPool<string>.Shared;
6868
var rentedArray = pool.Rent(definitions.Count);
6969
for (var i = 0; i < definitions.Count; i++)
7070
{
7171
var definition = definitions[i];
72-
rentedArray[i] = GridLengthTypeConverter.ConvertToString(definition.Height);
72+
rentedArray[i] = Converters.GridLengthTypeConverter.ConvertToString(definition.Height);
7373
}
7474
var result = string.Join(", ", rentedArray, 0, definitions.Count);
7575
pool.Return(rentedArray);

src/Controls/src/SourceGen/NodeSGExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ private static string ConvertEnum(string value, BaseNode node, ITypeSymbol toTyp
5050
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Converters.RectTypeConverter")!, (CreateLazyConverter<RectConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Rect")!) },
5151
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Converters.ColorTypeConverter")!, (CreateLazyConverter<ColorConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Color")!) },
5252
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Converters.PointTypeConverter")!, (CreateLazyConverter<PointConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Graphics.Point")!) },
53-
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.ThicknessTypeConverter")!, (CreateLazyConverter<ThicknessConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Thickness")!) },
5453
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.CornerRadiusTypeConverter")!, (CreateLazyRegistryConverter("Microsoft.Maui.CornerRadius"), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.CornerRadius")!) },
5554
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.EasingTypeConverter")!, (CreateLazyRegistryConverter("Microsoft.Maui.Easing"), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Easing")!) },
5655
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.FlexJustifyTypeConverter")!, (ConvertEnum, context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Layouts.FlexJustify")!) },
@@ -60,6 +59,8 @@ private static string ConvertEnum(string value, BaseNode node, ITypeSymbol toTyp
6059
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.FlexAlignSelfTypeConverter")!, (ConvertEnum, context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Layouts.FlexAlignSelf")!) },
6160
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.FlexWrapTypeConverter")!, (ConvertEnum, context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Layouts.FlexWrap")!) },
6261
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.FlexBasisTypeConverter")!, (CreateLazyRegistryConverter("Microsoft.Maui.Layouts.FlexBasis"), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Layouts.FlexBasis")!) },
62+
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.GridLengthTypeConverter")!, (CreateLazyConverter<GridLengthConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.GridLength")!) },
63+
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Converters.ThicknessTypeConverter")!, (CreateLazyConverter<ThicknessConverter>(), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Thickness")!) },
6364
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Controls.ColumnDefinitionCollectionTypeConverter")!, (CreateLazyRegistryConverter("Microsoft.Maui.Controls.ColumnDefinitionCollection"), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Controls.ColumnDefinitionCollection")!) },
6465
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Controls.FlowDirectionConverter")!, (CreateLazyRegistryConverter("Microsoft.Maui.FlowDirection"), context.Compilation.GetTypeByMetadataName("Microsoft.Maui.FlowDirection")!) },
6566
{ context.Compilation.GetTypeByMetadataName("Microsoft.Maui.Controls.FontSizeConverter")!, (CreateLazyRegistryConverter("System.Double"), context.Compilation.GetTypeByMetadataName("System.Double")!) },
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui29334"
5+
Title="Maui29334">
6+
<Grid x:Name="grid">
7+
<Grid.RowDefinitions>
8+
<RowDefinition>
9+
<RowDefinition.Height>
10+
<OnIdiom x:TypeArguments="GridLength" Default="50" Desktop="100"/>
11+
</RowDefinition.Height>
12+
</RowDefinition>
13+
<RowDefinition Height="*" />
14+
</Grid.RowDefinitions>
15+
16+
<Label Text="Hello, World!" />
17+
</Grid>
18+
19+
</ContentPage>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Microsoft.Maui.Controls.Xaml.UnitTests;
2+
3+
using Microsoft.Maui.ApplicationModel;
4+
using Microsoft.Maui.Controls.Core.UnitTests;
5+
using Microsoft.Maui.Dispatching;
6+
using Microsoft.Maui.UnitTests;
7+
using NUnit.Framework;
8+
9+
public partial class Maui29334 : ContentPage
10+
{
11+
12+
public Maui29334() => InitializeComponent();
13+
14+
public Maui29334(bool useCompiledXaml)
15+
{
16+
//this stub will be replaced at compile time
17+
}
18+
19+
[TestFixture]
20+
class Test
21+
{
22+
[SetUp]
23+
public void Setup()
24+
{
25+
Application.SetCurrentApplication(new MockApplication());
26+
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
27+
}
28+
29+
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);
30+
31+
[Test]
32+
public void OnIdiomGridLength([Values] bool useCompiledXaml)
33+
{
34+
var page = new Maui29334(useCompiledXaml);
35+
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)