Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 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 @@ -5036,6 +5036,20 @@ public void Refresh() { }
public override bool ShouldSerializeContent() { throw null; }
public void StopLoading() { }
}
public partial class ColumnDefinitionCollectionConverter : System.ComponentModel.TypeConverter
{
public ColumnDefinitionCollectionConverter() { }
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Type sourceType) { throw null; }
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; }
}

public partial class RowDefinitionCollectionConverter : System.ComponentModel.TypeConverter
{
public RowDefinitionCollectionConverter() { }
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Type sourceType) { throw null; }
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; }
}

public partial class Grid : System.Windows.Controls.Panel, System.Windows.Markup.IAddChild
{
public static readonly System.Windows.DependencyProperty ColumnProperty;
Expand All @@ -5045,9 +5059,11 @@ public partial class Grid : System.Windows.Controls.Panel, System.Windows.Markup
public static readonly System.Windows.DependencyProperty RowSpanProperty;
public static readonly System.Windows.DependencyProperty ShowGridLinesProperty;
public Grid() { }
[System.ComponentModel.TypeConverterAttribute(typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter))]
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
public System.Windows.Controls.ColumnDefinitionCollection ColumnDefinitions { get { throw null; } }
protected internal override System.Collections.IEnumerator LogicalChildren { get { throw null; } }
[System.ComponentModel.TypeConverterAttribute(typeof(System.Windows.Controls.RowDefinitionCollectionConverter))]
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
public System.Windows.Controls.RowDefinitionCollection RowDefinitions { get { throw null; } }
public bool ShowGridLines { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private void PrivateValidateValueForAddition(object value)
throw new ArgumentException(SR.Format(SR.GridCollection_MustBeCertainType, "ColumnDefinitionCollection", "ColumnDefinition"));
}

if (item.Parent != null)
if (item.Parent != _owner && item.Parent != null)
{
throw new ArgumentException(SR.Format(SR.GridCollection_InOtherCollection, "value", "ColumnDefinitionCollection"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,80 @@
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Markup;
using System.Globalization;

#pragma warning disable 1634, 1691 // suppressing PreSharp warnings

namespace System.Windows.Controls
{

public class ColumnDefinitionCollectionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string input)
{
IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
Grid grid = ipvt?.TargetObject as Grid;
if(grid != null)
{
var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance
var converter = new GridLengthConverter();

foreach (var length in input.Split(','))
{
if (converter.ConvertFromString(length.Trim()) is GridLength gridLength)
{
collection.Add(new ColumnDefinition { Width = gridLength });
}
}
return collection;
}
}

return base.ConvertFrom(context, culture, value);
}
}

public class RowDefinitionCollectionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string input)
{
IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
Grid grid = ipvt?.TargetObject as Grid;
if(grid != null)
{
var collection = new RowDefinitionCollection(grid); // Pass Grid instance
var converter = new GridLengthConverter();

foreach (var length in input.Split(','))
{
if (converter.ConvertFromString(length.Trim()) is GridLength gridLength)
{
collection.Add(new RowDefinition { Height = gridLength });
}
}

return collection;
}
}

return base.ConvertFrom(context, culture, value);
}
}

/// <summary>
/// Grid
/// </summary>
Expand Down Expand Up @@ -269,36 +338,72 @@ public bool ShowGridLines
set { SetValue(ShowGridLinesProperty, value); }
}

/// <summary>
/// Returns a ColumnDefinitionCollection of column definitions.
/// </summary>
[TypeConverter(typeof(ColumnDefinitionCollectionConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ColumnDefinitionCollection ColumnDefinitions
{
get
{
if (_data == null) { _data = new ExtendedData(); }
if (_data.ColumnDefinitions == null) { _data.ColumnDefinitions = new ColumnDefinitionCollection(this); }

return (_data.ColumnDefinitions);
if (_data == null) _data = new ExtendedData();
if (_data.ColumnDefinitions == null)
{
_data.ColumnDefinitions = new ColumnDefinitionCollection(this);
}
return _data.ColumnDefinitions;
}
set
{
if (value == null){
_data.ColumnDefinitions = new ColumnDefinitionCollection(this);
return;
}
if (_data == null) _data = new ExtendedData();
if (_data.ColumnDefinitions == null)
{
_data.ColumnDefinitions = new ColumnDefinitionCollection(this);
}
_data.ColumnDefinitions.Clear();
foreach (var columnDefinition in value)
{
_data.ColumnDefinitions.Add(columnDefinition);
}
}
}

/// <summary>
/// Returns a RowDefinitionCollection of row definitions.
/// </summary>
[TypeConverter(typeof(RowDefinitionCollectionConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public RowDefinitionCollection RowDefinitions
{
get
{
if (_data == null) { _data = new ExtendedData(); }
if (_data.RowDefinitions == null) { _data.RowDefinitions = new RowDefinitionCollection(this); }

return (_data.RowDefinitions);
if (_data == null) _data = new ExtendedData();
if (_data.RowDefinitions == null)
{
_data.RowDefinitions = new RowDefinitionCollection(this);
}
return _data.RowDefinitions;
}
set
{
if (value == null){
_data.RowDefinitions = new RowDefinitionCollection(this);
return;
}
if (_data == null) _data = new ExtendedData();
if (_data.RowDefinitions == null)
{
_data.RowDefinitions = new RowDefinitionCollection(this);
}
_data.RowDefinitions.Clear();
foreach (var rowDefinition in value)
{
_data.RowDefinitions.Add(rowDefinition);
}
}
}



#endregion Public Properties

//------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private void PrivateValidateValueForAddition(object value)
throw new ArgumentException(SR.Format(SR.GridCollection_MustBeCertainType, "RowDefinitionCollection", "RowDefinition"));
}

if (item.Parent != null)
if (item.Parent != _owner && item.Parent != null)
{
throw new ArgumentException(SR.Format(SR.GridCollection_InOtherCollection, "value", "RowDefinitionCollection"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,8 @@ public static Type GetKnownType(Int16 typeId)
case 757: t = () => typeof(XmlLanguageConverter); break;
case 758: t = () => typeof(XmlNamespaceMapping); break;
case 759: t = () => typeof(ZoomPercentageConverter); break;
case 760: t = () => typeof(RowDefinitionCollectionConverter); break;
case 761: t = () => typeof(ColumnDefinitionCollectionConverter); break;
default: t = () => null; break;
}

Expand Down Expand Up @@ -955,6 +957,8 @@ internal static TypeConverter CreateKnownTypeConverter(Int16 converterId)
case -722: o = new System.Windows.Media.VectorCollectionConverter(); break;
case -723: o = new System.Windows.VectorConverter(); break;
case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break;
case -760: o = new System.Windows.Controls.RowDefinitionCollectionConverter(); break;
case -761: o = new System.Windows.Controls.ColumnDefinitionCollectionConverter(); break;
}
return o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6403,7 +6403,15 @@ private WpfKnownMember Create_BamlProperty_Grid_ColumnDefinitions()
false // IsAttachable
);
bamlMember.GetDelegate = delegate(object target) { return ((System.Windows.Controls.Grid)target).ColumnDefinitions; };
bamlMember.SetDelegate = delegate(object target, object value) { var cd = ((System.Windows.Controls.Grid)target).ColumnDefinitions;
var cd2 = (System.Windows.Controls.ColumnDefinitionCollection)value;
cd.Clear();
foreach (var c in cd2)
{
cd.Add(c);
}};
bamlMember.IsWritePrivate = true;
bamlMember.TypeConverterType = typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter);
bamlMember.Freeze();
return bamlMember;
}
Expand All @@ -6420,7 +6428,15 @@ private WpfKnownMember Create_BamlProperty_Grid_RowDefinitions()
false // IsAttachable
);
bamlMember.GetDelegate = delegate(object target) { return ((System.Windows.Controls.Grid)target).RowDefinitions; };
bamlMember.SetDelegate = delegate(object target, object value) { var cd = ((System.Windows.Controls.Grid)target).RowDefinitions;
var cd2 = (System.Windows.Controls.RowDefinitionCollection)value;
cd.Clear();
foreach (var c in cd2)
{
cd.Add(c);
}};
bamlMember.IsWritePrivate = true;
bamlMember.TypeConverterType = typeof(System.Windows.Controls.RowDefinitionCollectionConverter);
bamlMember.Freeze();
return bamlMember;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ private WpfKnownType CreateKnownBamlType(short bamlNumber, bool isBamlType, bool
case 757: return Create_BamlType_XmlLanguageConverter(isBamlType, useV3Rules); // type converter
case 758: return Create_BamlType_XmlNamespaceMapping(isBamlType, useV3Rules);
case 759: return Create_BamlType_ZoomPercentageConverter(isBamlType, useV3Rules);
case 760: return Create_BamlType_RowDefinitionCollectionConverter(isBamlType, useV3Rules);
case 761: return Create_BamlType_ColumnDefinitionCollectionConverter(isBamlType, useV3Rules);
default:
throw new InvalidOperationException("Invalid BAML number");
}
Expand Down Expand Up @@ -11851,5 +11853,29 @@ private WpfKnownType Create_BamlType_KeyboardNavigation(bool isBamlType, bool us
bamlType.Freeze();
return bamlType;
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private WpfKnownType Create_BamlType_RowDefinitionCollectionConverter(bool isBamlType, bool useV3Rules)
{
var bamlType = new WpfKnownType(this, // SchemaContext
760, "RowDefinitionCollectionConverter",
typeof(System.Windows.Controls.RowDefinitionCollectionConverter),
isBamlType, useV3Rules);
bamlType.DefaultConstructor = delegate() { return new System.Windows.Controls.RowDefinitionCollectionConverter(); };
bamlType.Freeze();
return bamlType;
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private WpfKnownType Create_BamlType_ColumnDefinitionCollectionConverter(bool isBamlType, bool useV3Rules)
{
var bamlType = new WpfKnownType(this, // SchemaContext
761, "ColumnDefinitionCollectionConverter",
typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter),
isBamlType, useV3Rules);
bamlType.DefaultConstructor = delegate() { return new System.Windows.Controls.ColumnDefinitionCollectionConverter(); };
bamlType.Freeze();
return bamlType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ internal enum KnownElements : short
XmlLanguageConverter,
XmlNamespaceMapping,
ZoomPercentageConverter,
MaxElement
MaxElement,
RowDefinitionCollectionConverter,
ColumnDefinitionCollectionConverter
}

// This enum specifies the IDs we use for known CLR and DP Properties in BAML.
Expand Down Expand Up @@ -1670,6 +1672,8 @@ internal static object CreateKnownElement(KnownElements knownElement)
case KnownElements.XmlLanguageConverter: o = new System.Windows.Markup.XmlLanguageConverter(); break;
case KnownElements.XmlNamespaceMapping: o = new System.Windows.Data.XmlNamespaceMapping(); break;
case KnownElements.ZoomPercentageConverter: o = new System.Windows.Documents.ZoomPercentageConverter(); break;
case KnownElements.RowDefinitionCollectionConverter: o = new System.Windows.Controls.RowDefinitionCollectionConverter(); break;
case KnownElements.ColumnDefinitionCollectionConverter: o = new System.Windows.Controls.ColumnDefinitionCollectionConverter(); break;
}
return o;
}
Expand Down Expand Up @@ -5537,6 +5541,8 @@ private Type InitializeOneType(KnownElements knownElement)
case KnownElements.DateTimeConverter: t = typeof(DateTimeConverter); break;
case KnownElements.DateTimeConverter2: t = typeof(DateTimeConverter2); break;
case KnownElements.UriTypeConverter: t = typeof(UriTypeConverter); break;
case KnownElements.RowDefinitionCollectionConverter: t = _asmFramework.GetType("System.Windows.Controls.RowDefinitionCollectionConverter"); break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why have you used this method ? typeof should have worked.

case KnownElements.ColumnDefinitionCollectionConverter: t = _asmFramework.GetType("System.Windows.Controls.ColumnDefinitionCollectionConverter"); break;
}

if(t == null)
Expand Down Expand Up @@ -6311,6 +6317,8 @@ private Type InitializeOneType(KnownElements knownElement)
case KnownElements.XmlLanguageConverter: t = typeof(System.Windows.Markup.XmlLanguageConverter); break;
case KnownElements.XmlNamespaceMapping: t = typeof(System.Windows.Data.XmlNamespaceMapping); break;
case KnownElements.ZoomPercentageConverter: t = typeof(System.Windows.Documents.ZoomPercentageConverter); break;
case KnownElements.RowDefinitionCollectionConverter : t = typeof(System.Windows.Controls.RowDefinitionCollectionConverter); break;
case KnownElements.ColumnDefinitionCollectionConverter : t = typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter); break;
}

return t;
Expand Down
Loading