Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'S
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.AccessText.FontSize' changed from '[LocalizabilityAttribute(0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.BooleanToVisibilityConverter' changed from '[LocalizabilityAttribute(17)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.CheckBox' changed from '[LocalizabilityAttribute(5)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.CheckBox)]' in the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.ColumnDefinition' in the contract but not the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.ComboBox' changed from '[LocalizabilityAttribute(6)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.ComboBox)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.ComboBoxItem' changed from '[LocalizabilityAttribute(6)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.ComboBox)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.ContentControl' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation.
Expand Down Expand Up @@ -145,6 +146,7 @@ CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'S
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.RadioButton.GroupName' changed from '[LocalizabilityAttribute(17)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.RichTextBox' changed from '[LocalizabilityAttribute(15)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.Inherit)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.RichTextBox.CaretPosition' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.RowDefinition' in the contract but not the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.ScrollContentPresenter.HorizontalOffset' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.ScrollContentPresenter.ScrollOwner' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.ScrollContentPresenter.VerticalOffset' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
Expand Down Expand Up @@ -261,4 +263,4 @@ CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVi
CannotChangeAttribute : Attribute 'System.Windows.Markup.DesignerSerializationOptionsAttribute' on 'System.Windows.Markup.XmlAttributeProperties.GetXmlSpace(System.Windows.DependencyObject)' changed from '[DesignerSerializationOptionsAttribute(1)]' in the contract to '[DesignerSerializationOptionsAttribute(DesignerSerializationOptions.SerializeAsAttribute)]' in the implementation.
CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Media.Animation.Storyboard.GetTarget(System.Windows.DependencyObject)' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation.
CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Shapes.Shape' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation.
Total Issues: 262
Total Issues: 264
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@
<Compile Include="System\Windows\Controls\CleanUpVirtualizedItemEventArgs.cs" />
<Compile Include="System\Windows\Controls\ClickMode.cs" />
<Compile Include="System\Windows\Controls\ColumnDefinition.cs" />
<Compile Include="System\Windows\Controls\ColumnDefinitionConverter.cs" />
<Compile Include="System\Windows\Controls\ComboBox.cs" />
<Compile Include="System\Windows\Controls\ComboBoxItem.cs" />
<Compile Include="System\Windows\Controls\ContainerTracking.cs" />
Expand Down Expand Up @@ -740,6 +741,7 @@
<Compile Include="System\Windows\Controls\RealizedColumnsBlock.cs" />
<Compile Include="System\Windows\Controls\RichTextBox.cs" />
<Compile Include="System\Windows\Controls\RowDefinition.cs" />
<Compile Include="System\Windows\Controls\RowDefinitionConverter.cs" />
<Compile Include="System\Windows\Controls\ScrollChangedEventArgs.cs" />
<Compile Include="System\Windows\Controls\ScrollUnit.cs" />
<Compile Include="System\Windows\Controls\ScrollViewer.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ private void PrivateValidate()
/// ColumnDefinition is a FrameworkContentElement used by Grid
/// to hold column / row specific properties.
/// </summary>
[TypeConverter(typeof(ColumnDefinitionConverter))]
public class ColumnDefinition : DefinitionBase
{
//------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Globalization;
using System.Text;
using MS.Internal;

namespace System.Windows.Controls
{
internal sealed class ColumnDefinitionConverter : TypeConverter
{
#region Public Methods

/// <summary>
/// CanConvertFrom - Returns whether or not this class can convert from a given type.
/// </summary>
/// <returns>
/// bool - True if this converter can convert from the provided type, false if not.
/// </returns>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="sourceType"> The Type being queried for support. </param>
public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType)
{
return sourceType == typeof(string);
}

/// <summary>
/// CanConvertTo - Returns whether or not this class can convert to a given type.
/// </summary>
/// <returns>
/// bool - True if this converter can convert to the provided type, false if not.
/// </returns>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="destinationType"> The Type being queried for support. </param>
public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType)
{
return destinationType == typeof(string);
}

/// <summary>
/// ConvertFrom - Attempt to convert to a ColumnDefinitionCollection from the given object.
/// </summary>
/// <returns>
/// The object which was constructed.
/// </returns>
/// <exception cref="ArgumentNullException">
/// An ArgumentNullException is thrown if the example object is null.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The Thickness to convert. </param>
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
{
if (value is string input)
{
ColumnDefinition columnDefinition = new ColumnDefinition{ Width = GridLengthConverter.FromString(input, cultureInfo) };
return columnDefinition;
}
throw GetConvertFromException(value);
}

/// <summary>
/// ConvertTo - Attempt to convert a ColumnDefinitionCollection to the given type
/// </summary>
/// <returns>
/// The object which was constructed.
/// </returns>
/// <exception cref="ArgumentNullException">
/// An ArgumentNullException is thrown if the example object is null.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The ColumnDefinitionCollection to convert. </param>
/// <param name="destinationType">The type to which to convert the ColumnDefinitionCollection instance. </param>
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(destinationType);
if (destinationType == typeof(string) && value is ColumnDefinition columnDefinition)
{
return GridLengthConverter.ToString(columnDefinition.Width, cultureInfo);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do more checks, you cannot express columns/rows that have min/max/offset set

}
throw GetConvertToException(value, destinationType);
}

#endregion Public Methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ private void PrivateValidate()
/// RowDefinition is a FrameworkContentElement used by Grid
/// to hold column / row specific properties.
/// </summary>
[TypeConverter(typeof(RowDefinitionConverter))]
public class RowDefinition : DefinitionBase
{
//------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Globalization;
using System.Text;
using MS.Internal;

namespace System.Windows.Controls
{
internal sealed class RowDefinitionConverter : TypeConverter
{
#region Public Methods

/// <summary>
/// CanConvertFrom - Returns whether or not this class can convert from a given type.
/// </summary>
/// <returns>
/// bool - True if this converter can convert from the provided type, false if not.
/// </returns>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="sourceType"> The Type being queried for support. </param>
public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType)
{
return sourceType == typeof(string);
}

/// <summary>
/// CanConvertTo - Returns whether or not this class can convert to a given type.
/// </summary>
/// <returns>
/// bool - True if this converter can convert to the provided type, false if not.
/// </returns>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="destinationType"> The Type being queried for support. </param>
public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType)
{
return destinationType == typeof(string);
}

/// <summary>
/// ConvertFrom - Attempt to convert to a RowDefinitionCollection from the given object.
/// </summary>
/// <returns>
/// The object which was constructed.
/// </returns>
/// <exception cref="ArgumentNullException">
/// An ArgumentNullException is thrown if the example object is null.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The Thickness to convert. </param>
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
{
if (value is string input)
{
RowDefinition rowDefinition = new RowDefinition{ Height = GridLengthConverter.FromString(input, cultureInfo) };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use type descriptor to decide whether you should return column or row and have only one converter (possibly even the grid length one), but if this ends up being public, it possibly is a better API separately

return rowDefinition;
}
throw GetConvertFromException(value);
}

/// <summary>
/// ConvertTo - Attempt to convert a RowDefinitionCollection to the given type
/// </summary>
/// <returns>
/// The object which was constructed.
/// </returns>
/// <exception cref="ArgumentNullException">
/// An ArgumentNullException is thrown if the example object is null.
/// </exception>
/// <param name="typeDescriptorContext"> The ITypeDescriptorContext for this call. </param>
/// <param name="cultureInfo"> The CultureInfo which is respected when converting. </param>
/// <param name="value"> The RowDefinitionCollection to convert. </param>
/// <param name="destinationType">The type to which to convert the RowDefinitionCollection instance. </param>
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(value);
ArgumentNullException.ThrowIfNull(destinationType);
if (destinationType == typeof(string) && value is RowDefinition rowDefinition)
{
return GridLengthConverter.ToString(rowDefinition.Height, cultureInfo);
}
throw GetConvertToException(value, destinationType);
}

#endregion Public Methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,7 @@ private WpfKnownType Create_BamlType_ColumnDefinition(bool isBamlType, bool useV
bamlType.RuntimeNamePropertyName = "Name";
bamlType.XmlLangPropertyName = "Language";
bamlType.IsUsableDuringInit = true;
bamlType.TypeConverterType = typeof(System.Windows.Controls.ColumnDefinitionConverter);
bamlType.Freeze();
return bamlType;
}
Expand Down Expand Up @@ -8634,6 +8635,7 @@ private WpfKnownType Create_BamlType_RowDefinition(bool isBamlType, bool useV3Ru
bamlType.RuntimeNamePropertyName = "Name";
bamlType.XmlLangPropertyName = "Language";
bamlType.IsUsableDuringInit = true;
bamlType.TypeConverterType = typeof(System.Windows.Controls.RowDefinitionConverter);
bamlType.Freeze();
return bamlType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ internal bool IsXmlDataIsland()
{
return (_xmlDataIslandDepth != -1);
}

internal bool CanInitializeCollectionFromString(Type type)
{
return IsACollection(type) && XamlTypeMapper.GetTypeConverterType(type) == null
&& XamlTypeMapper.GetTypeConverterType(GetCollectionItemType(type)) != null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you could test for though is whether the item type converter can convert from string

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But again you need to decide whether it is desirable to throw "no setter" error or converter error. Maybe the latter is better in this case too.

#endregion internalMethods

#region CacheCallbacks
Expand Down Expand Up @@ -3225,13 +3231,13 @@ private void WritePropertyAttribute(
propertyCanWrite = false;
}

if (!propertyCanWrite)
if (!propertyCanWrite && !CanInitializeCollectionFromString(propInfo.PropertyType))
{
ThrowExceptionWithLine(SR.Format(SR.ParserReadOnlyProp, attribLocalName));
}
}

if (propInfo != null && !XamlTypeMapper.IsAllowedPropertySet(propInfo))
if (propInfo != null && !CanInitializeCollectionFromString(propInfo.PropertyType) && !XamlTypeMapper.IsAllowedPropertySet(propInfo))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably add the new condition at the end for consistency and performance

{
ThrowException(nameof(SR.ParserCantSetAttribute), "property", $"{declaringType.Name}.{attribLocalName}", "set");
}
Expand Down
Loading