From c4f44e456c2b29925ec86ac2b9a1c8290e59f7a3 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Tue, 3 Sep 2024 20:37:07 +0530 Subject: [PATCH 1/6] Intially Commit --- .../PresentationFramework-ref.baseline.txt | 9 +- ...ows.Controls.Ribbon-ref-Net48.baseline.txt | 1 - .../UIAutomationProvider-ref.baseline.txt | 4 +- .../Windows/Controls/ColumnDefinition.cs | 2 +- .../System/Windows/Controls/Grid.cs | 165 ++++++++++++++++-- .../Markup/Baml2006/Baml2006KnownTypes.cs | 4 + .../Baml2006/WpfGeneratedKnownProperties.cs | 16 ++ .../Markup/Baml2006/WpfGeneratedKnownTypes.cs | 26 +++ .../System/Windows/Markup/KnownTypes.cs | 10 +- 9 files changed, 217 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt index d4b7ffccb6b..64da99c8144 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt @@ -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. +TypesMustExist : Type 'System.Windows.Controls.ColumnDefinitionCollectionConverter' does not exist in the implementation but it does exist in the contract. 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. @@ -92,8 +93,13 @@ CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'S CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.DefinitionBase' changed from '[LocalizabilityAttribute(16)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.Ignore)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.Expander' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.Frame' changed from '[LocalizabilityAttribute(16)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.Ignore)]' in the implementation. +MembersMustExist : Member 'public System.Windows.DependencyProperty System.Windows.DependencyProperty System.Windows.Controls.Grid.ColumnDefinitionsProperty' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.Grid.ColumnDefinitions' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. +CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.Grid.ColumnDefinitions' in the contract but not the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.Grid.RowDefinitions' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. +CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.Grid.RowDefinitions' in the contract but not the implementation. +MembersMustExist : Member 'public void System.Windows.Controls.Grid.ColumnDefinitions.set(System.Windows.Controls.ColumnDefinitionCollection)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void System.Windows.Controls.Grid.RowDefinitions.set(System.Windows.Controls.RowDefinitionCollection)' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.GridView.ColumnHeaderTemplateSelector' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.GridView.Columns' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.GridViewColumn' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation. @@ -145,6 +151,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. +TypesMustExist : Type 'System.Windows.Controls.RowDefinitionCollectionConverter' does not exist in the implementation but it does exist in the contract. 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. @@ -261,4 +268,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: 269 diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt index 66f72086f77..fcc74cf8643 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt @@ -1,2 +1 @@ -Compat issues with assembly System.Windows.Controls.Ribbon: Total Issues: 0 diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt index 641d6650c27..0e3a75ca1dd 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt @@ -11,7 +11,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragment' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragmentRoot' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderHwndOverride' in the contract but not the implementation. -CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderSimple' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ISelectionItemProvider' in the contract but not the implementation. @@ -20,10 +19,9 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextProvider' in the contract but not the implementation. -CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextRangeProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IToggleProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITransformProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IValueProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IVirtualizedItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IWindowProvider' in the contract but not the implementation. -Total Issues: 27 +Total Issues: 25 diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs index 6962180fe76..af42b0acb58 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinition.cs @@ -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")); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index 7e7a8040c82..28da6d20f59 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -31,11 +31,74 @@ 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; + 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) + { + ColumnDefinition columnDefinition = new ColumnDefinition { Width = 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 && context?.Instance is Grid grid) + { + 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); + } + } + /// /// Grid /// @@ -60,6 +123,7 @@ static Grid() public Grid() { SetFlags((bool) ShowGridLinesProperty.GetDefaultValue(DependencyObjectType), Flags.ShowGridLinesPropertyValue); + //_data = new ExtendedData(); // Ensure _data is initialize } #endregion Constructors @@ -250,6 +314,27 @@ public static bool GetIsSharedSizeScope(UIElement element) return ((bool)element.GetValue(IsSharedSizeScopeProperty)); } + // private static void OnColumnDefinitionsInlineChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + // { + // if (d is Grid grid) + // { + // grid.UpdateColumnDefinitions((ColumnDefinitionCollection)e.NewValue); + // } + // } + // private void UpdateColumnDefinitions(ColumnDefinitionCollection definitions) + // { + // if (_data == null) _data = new ExtendedData(); + // if (_data.ColumnDefinitions == null) + // { + // _data.ColumnDefinitions = new ColumnDefinitionCollection(this); + // } + // _data.ColumnDefinitions.Clear(); + // foreach (var columnDefinition in definitions) + // { + // _data.ColumnDefinitions.Add(columnDefinition); + // } + // } + #endregion Public Methods //------------------------------------------------------ @@ -269,36 +354,81 @@ public bool ShowGridLines set { SetValue(ShowGridLinesProperty, value); } } - /// - /// Returns a ColumnDefinitionCollection of column definitions. - /// + [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) throw new ArgumentNullException(nameof(value)); + 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); + } } } - /// - /// Returns a RowDefinitionCollection of row definitions. - /// + [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); } + if (_data == null) _data = new ExtendedData(); + if (_data.RowDefinitions == null) + { + _data.RowDefinitions = new RowDefinitionCollection(this); + } + return _data.RowDefinitions; + } + set + { + if (value == null) throw new ArgumentNullException(nameof(value)); + 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); + } + } + } - return (_data.RowDefinitions); + // Helper method to parse grid lengths from shorthand syntax + private static IEnumerable ParseGridLengths(string input) + { + var converter = new GridLengthConverter(); // Create an instance of the converter + var lengths = input.Split(','); + + foreach (var length in lengths) + { + if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + { + yield return gridLength; + } } } + + #endregion Public Properties //------------------------------------------------------ @@ -3488,6 +3618,15 @@ private enum Flags false, new PropertyChangedCallback(DefinitionBase.OnIsSharedSizeScopePropertyChanged))); + // public static readonly DependencyProperty ColumnDefinitionsProperty = + // DependencyProperty.RegisterAttached( + // "ColumnDefinitions", + // typeof(ColumnDefinitionCollection), + // typeof(Grid), + // new FrameworkPropertyMetadata( + // null, + // OnColumnDefinitionsInlineChanged)); + #endregion Properties //------------------------------------------------------ diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006KnownTypes.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006KnownTypes.cs index 8848d13601b..bfb394b3f66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006KnownTypes.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006KnownTypes.cs @@ -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; } @@ -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; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs index 2fd51dff509..f4c4286891f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs @@ -6403,7 +6403,16 @@ 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.DependencyProperty = System.Windows.Controls.Grid.ColumnDefinitionsProperty; + bamlMember.TypeConverterType = typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter); bamlMember.Freeze(); return bamlMember; } @@ -6420,6 +6429,13 @@ 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.Freeze(); return bamlMember; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownTypes.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownTypes.cs index 0b2c324ad85..cb6a869229f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownTypes.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownTypes.cs @@ -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"); } @@ -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; + } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/KnownTypes.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/KnownTypes.cs index cbd2d5bcd41..2337189aaa9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/KnownTypes.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/KnownTypes.cs @@ -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. @@ -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; } @@ -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; + case KnownElements.ColumnDefinitionCollectionConverter: t = _asmFramework.GetType("System.Windows.Controls.ColumnDefinitionCollectionConverter"); break; } if(t == null) @@ -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; From fd9e3ee386c72463fde68a266ae4ee61ed845d1e Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Wed, 4 Sep 2024 13:08:21 +0530 Subject: [PATCH 2/6] RowDefinitionsChanges --- .../System/Windows/Controls/Grid.cs | 98 ++++++------------- .../System/Windows/Controls/RowDefinition.cs | 2 +- .../Baml2006/WpfGeneratedKnownProperties.cs | 2 +- 3 files changed, 34 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index 28da6d20f59..30e70ca62ab 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -51,19 +51,20 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c { IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; Grid grid = ipvt?.TargetObject as Grid; - var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance - var converter = new GridLengthConverter(); - - foreach (var length in input.Split(',')) + if(grid != null) { - if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance + var converter = new GridLengthConverter(); + + foreach (var length in input.Split(',')) { - ColumnDefinition columnDefinition = new ColumnDefinition { Width = gridLength }; - collection.Add(new ColumnDefinition { Width = gridLength }); + if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + { + collection.Add(new ColumnDefinition { Width = gridLength }); + } } + return collection; } - - return collection; } return base.ConvertFrom(context, culture, value); @@ -79,20 +80,25 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - if (value is string input && context?.Instance is Grid grid) + if (value is string input) { - var collection = new RowDefinitionCollection(grid); // Pass Grid instance - var converter = new GridLengthConverter(); - - foreach (var length in input.Split(',')) + IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; + Grid grid = ipvt?.TargetObject as Grid; + if(grid != null) { - if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + var collection = new RowDefinitionCollection(grid); // Pass Grid instance + var converter = new GridLengthConverter(); + + foreach (var length in input.Split(',')) { - collection.Add(new RowDefinition { Height = gridLength }); + if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + { + collection.Add(new RowDefinition { Height = gridLength }); + } } - } - return collection; + return collection; + } } return base.ConvertFrom(context, culture, value); @@ -123,7 +129,6 @@ static Grid() public Grid() { SetFlags((bool) ShowGridLinesProperty.GetDefaultValue(DependencyObjectType), Flags.ShowGridLinesPropertyValue); - //_data = new ExtendedData(); // Ensure _data is initialize } #endregion Constructors @@ -314,27 +319,6 @@ public static bool GetIsSharedSizeScope(UIElement element) return ((bool)element.GetValue(IsSharedSizeScopeProperty)); } - // private static void OnColumnDefinitionsInlineChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - // { - // if (d is Grid grid) - // { - // grid.UpdateColumnDefinitions((ColumnDefinitionCollection)e.NewValue); - // } - // } - // private void UpdateColumnDefinitions(ColumnDefinitionCollection definitions) - // { - // if (_data == null) _data = new ExtendedData(); - // if (_data.ColumnDefinitions == null) - // { - // _data.ColumnDefinitions = new ColumnDefinitionCollection(this); - // } - // _data.ColumnDefinitions.Clear(); - // foreach (var columnDefinition in definitions) - // { - // _data.ColumnDefinitions.Add(columnDefinition); - // } - // } - #endregion Public Methods //------------------------------------------------------ @@ -369,7 +353,10 @@ public ColumnDefinitionCollection ColumnDefinitions } set { - if (value == null) throw new ArgumentNullException(nameof(value)); + if (value == null){ + _data.ColumnDefinitions = new ColumnDefinitionCollection(this); + return; + } if (_data == null) _data = new ExtendedData(); if (_data.ColumnDefinitions == null) { @@ -398,7 +385,10 @@ public RowDefinitionCollection RowDefinitions } set { - if (value == null) throw new ArgumentNullException(nameof(value)); + if (value == null){ + _data.RowDefinitions = new RowDefinitionCollection(this); + return; + } if (_data == null) _data = new ExtendedData(); if (_data.RowDefinitions == null) { @@ -412,21 +402,6 @@ public RowDefinitionCollection RowDefinitions } } - // Helper method to parse grid lengths from shorthand syntax - private static IEnumerable ParseGridLengths(string input) - { - var converter = new GridLengthConverter(); // Create an instance of the converter - var lengths = input.Split(','); - - foreach (var length in lengths) - { - if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) - { - yield return gridLength; - } - } - } - #endregion Public Properties @@ -3618,15 +3593,6 @@ private enum Flags false, new PropertyChangedCallback(DefinitionBase.OnIsSharedSizeScopePropertyChanged))); - // public static readonly DependencyProperty ColumnDefinitionsProperty = - // DependencyProperty.RegisterAttached( - // "ColumnDefinitions", - // typeof(ColumnDefinitionCollection), - // typeof(Grid), - // new FrameworkPropertyMetadata( - // null, - // OnColumnDefinitionsInlineChanged)); - #endregion Properties //------------------------------------------------------ diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinition.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinition.cs index b50920ea489..34621c1c87b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinition.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinition.cs @@ -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")); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs index f4c4286891f..93bcf0e4f1e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs @@ -6411,7 +6411,6 @@ private WpfKnownMember Create_BamlProperty_Grid_ColumnDefinitions() cd.Add(c); }}; bamlMember.IsWritePrivate = true; - //bamlMember.DependencyProperty = System.Windows.Controls.Grid.ColumnDefinitionsProperty; bamlMember.TypeConverterType = typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter); bamlMember.Freeze(); return bamlMember; @@ -6437,6 +6436,7 @@ private WpfKnownMember Create_BamlProperty_Grid_RowDefinitions() cd.Add(c); }}; bamlMember.IsWritePrivate = true; + bamlMember.TypeConverterType = typeof(System.Windows.Controls.RowDefinitionCollectionConverter); bamlMember.Freeze(); return bamlMember; } From 604c290acac3609128eff7916044402c543c11b6 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Wed, 4 Sep 2024 19:54:03 +0530 Subject: [PATCH 3/6] PresentationFramework.cs changes --- .../PresentationFramework-ref.baseline.txt | 9 +------- ...ows.Controls.Ribbon-ref-Net48.baseline.txt | 1 + .../UIAutomationProvider-ref.baseline.txt | 4 +++- .../PresentationFramework.cs | 16 ++++++++++++++ .../ref/PresentationFramework.cs | 21 +++++++++++++++++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt index 64da99c8144..d4b7ffccb6b 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/PresentationFramework-ref.baseline.txt @@ -76,7 +76,6 @@ 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. -TypesMustExist : Type 'System.Windows.Controls.ColumnDefinitionCollectionConverter' does not exist in the implementation but it does exist in the contract. 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. @@ -93,13 +92,8 @@ CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'S CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.DefinitionBase' changed from '[LocalizabilityAttribute(16)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.Ignore)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.Expander' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.Frame' changed from '[LocalizabilityAttribute(16)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.Ignore)]' in the implementation. -MembersMustExist : Member 'public System.Windows.DependencyProperty System.Windows.DependencyProperty System.Windows.Controls.Grid.ColumnDefinitionsProperty' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.Grid.ColumnDefinitions' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. -CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.Grid.ColumnDefinitions' in the contract but not the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.Grid.RowDefinitions' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. -CannotRemoveAttribute : Attribute 'System.ComponentModel.TypeConverterAttribute' exists on 'System.Windows.Controls.Grid.RowDefinitions' in the contract but not the implementation. -MembersMustExist : Member 'public void System.Windows.Controls.Grid.ColumnDefinitions.set(System.Windows.Controls.ColumnDefinitionCollection)' does not exist in the implementation but it does exist in the contract. -MembersMustExist : Member 'public void System.Windows.Controls.Grid.RowDefinitions.set(System.Windows.Controls.RowDefinitionCollection)' does not exist in the implementation but it does exist in the contract. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.GridView.ColumnHeaderTemplateSelector' changed from '[DesignerSerializationVisibilityAttribute(0)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]' in the implementation. CannotChangeAttribute : Attribute 'System.ComponentModel.DesignerSerializationVisibilityAttribute' on 'System.Windows.Controls.GridView.Columns' changed from '[DesignerSerializationVisibilityAttribute(2)]' in the contract to '[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]' in the implementation. CannotChangeAttribute : Attribute 'System.Windows.LocalizabilityAttribute' on 'System.Windows.Controls.GridViewColumn' changed from '[LocalizabilityAttribute(0, Readability=0)]' in the contract to '[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)]' in the implementation. @@ -151,7 +145,6 @@ 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. -TypesMustExist : Type 'System.Windows.Controls.RowDefinitionCollectionConverter' does not exist in the implementation but it does exist in the contract. 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. @@ -268,4 +261,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: 269 +Total Issues: 262 diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt index fcc74cf8643..66f72086f77 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/System.Windows.Controls.Ribbon-ref-Net48.baseline.txt @@ -1 +1,2 @@ +Compat issues with assembly System.Windows.Controls.Ribbon: Total Issues: 0 diff --git a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt index 0e3a75ca1dd..641d6650c27 100644 --- a/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt +++ b/src/Microsoft.DotNet.Wpf/ApiCompat/Baselines/UIAutomationProvider-ref.baseline.txt @@ -11,6 +11,7 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragment' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderFragmentRoot' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderHwndOverride' in the contract but not the implementation. +CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IRawElementProviderSimple' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IScrollProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ISelectionItemProvider' in the contract but not the implementation. @@ -19,9 +20,10 @@ CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeA CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITableProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextProvider' in the contract but not the implementation. +CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITextRangeProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IToggleProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.ITransformProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IValueProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IVirtualizedItemProvider' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.InteropServices.InterfaceTypeAttribute' exists on 'System.Windows.Automation.Provider.IWindowProvider' in the contract but not the implementation. -Total Issues: 25 +Total Issues: 27 diff --git a/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs b/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs index 78efe1b3984..0d32d27edf8 100644 --- a/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs +++ b/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs @@ -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; @@ -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 { } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs index 15b0071ed2d..c3fbb21309c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs @@ -5106,6 +5106,21 @@ 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; @@ -5115,11 +5130,13 @@ 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; } } + public System.Windows.Controls.ColumnDefinitionCollection ColumnDefinitions { get { throw null; } set { } } 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 System.Windows.Controls.RowDefinitionCollection RowDefinitions { get { throw null; } set { } } public bool ShowGridLines { get { throw null; } set { } } protected override int VisualChildrenCount { get { throw null; } } protected override System.Windows.Size ArrangeOverride(System.Windows.Size arrangeSize) { throw null; } From 1ce19a28cba28a7e2ab888cd338bb3fca1b8bf12 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Thu, 5 Sep 2024 18:50:54 +0530 Subject: [PATCH 4/6] Creating new files for ColumnDefinitionCollectionConverter and RowDefinitionCollectionConverter --- .../PresentationFramework.cs | 12 +- .../PresentationFramework.csproj | 2 + .../ColumnDefinitionCollectionConverter.cs | 143 ++++++++++++++++++ .../System/Windows/Controls/Grid.cs | 70 +-------- .../RowDefinitionCollectionConverter.cs | 143 ++++++++++++++++++ .../ref/PresentationFramework.cs | 4 + 6 files changed, 301 insertions(+), 73 deletions(-) create mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs create mode 100644 src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs diff --git a/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs b/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs index 0d32d27edf8..e84f6b73a12 100644 --- a/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs +++ b/src/Microsoft.DotNet.Wpf/cycle-breakers/PresentationFramework/PresentationFramework.cs @@ -5039,15 +5039,19 @@ 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 override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Type sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { 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 override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Type sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } } public partial class Grid : System.Windows.Controls.Panel, System.Windows.Markup.IAddChild diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj index 6e84493822b..031bbf308c1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/PresentationFramework.csproj @@ -547,6 +547,7 @@ + @@ -739,6 +740,7 @@ + diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs new file mode 100644 index 00000000000..36a9b2d14e6 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs @@ -0,0 +1,143 @@ +// 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. + +// +// +// +// Description: Contains the ColumnDefinitionCollectionConverter: TypeConverter for the ColumnDefinitionCollection. +// +// + +using MS.Internal; +using MS.Internal.Controls; +using MS.Internal.PresentationFramework; +using MS.Internal.Telemetry.PresentationFramework; +using MS.Utility; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Windows.Threading; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +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 + { + #region Public Methods + + /// + /// CanConvertFrom - Returns whether or not this class can convert from a given type. + /// + /// + /// bool - True if thie converter can convert from the provided type, false if not. + /// + /// The ITypeDescriptorContext for this call. + /// The Type being queried for support. + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + /// + /// CanConvertTo - Returns whether or not this class can convert to a given type. + /// + /// + /// bool - True if this converter can convert to the provided type, false if not. + /// + /// The ITypeDescriptorContext for this call. + /// The Type being queried for support. + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + return destinationType == typeof(string) || base.CanConvertTo(context, destinationType); + } + + /// + /// ConvertFrom - Attempt to convert to a ColumnDefinitionCollection from the given object. + /// + /// + /// The object which was constructoed. + /// + /// + /// An ArgumentNullException is thrown if the example object is null. + /// + /// + /// An ArgumentException is thrown if the object is not null and is not a valid type, + /// or if the destinationType isn't one of the valid destination types. + /// + /// The ITypeDescriptorContext for this call. + /// The CultureInfo which is respected when converting. + /// The Thickness to convert. + 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); + } + + /// + /// ConvertTo - Attempt to convert a ColumnDefinitionCollection to the given type + /// + /// + /// The object which was constructoed. + /// + /// + /// An ArgumentNullException is thrown if the example object is null. + /// + /// + /// An ArgumentException is thrown if the object is not null and is not a Thickness, + /// or if the destinationType isn't one of the valid destination types. + /// + /// The ITypeDescriptorContext for this call. + /// The CultureInfo which is respected when converting. + /// The ColumnDefintionCollection to convert. + /// The type to which to convert the ColumnDefintionCollection instance. + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string) && value is ColumnDefinitionCollection columnDefinitions) + { + var parts = new string[columnDefinitions.Count]; + + for (int i = 0; i < columnDefinitions.Count; i++) + { + parts[i] = columnDefinitions[i].Width.ToString(); + } + + return string.Join(",", parts); + } + + return base.ConvertTo(context, culture, value, destinationType); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index 30e70ca62ab..a92678edba0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -36,75 +36,7 @@ #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); - } - } - +{ /// /// Grid /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs new file mode 100644 index 00000000000..edff5c39645 --- /dev/null +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs @@ -0,0 +1,143 @@ +// 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. + +// +// +// +// Description: Contains the RowDefinitionCollectionConverter: TypeConverter for the RowDefinitionCollection. +// +// + +using MS.Internal; +using MS.Internal.Controls; +using MS.Internal.PresentationFramework; +using MS.Internal.Telemetry.PresentationFramework; +using MS.Utility; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Windows.Threading; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +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 RowDefinitionCollectionConverter : TypeConverter + { + #region Public Methods + + /// + /// CanConvertFrom - Returns whether or not this class can convert from a given type. + /// + /// + /// bool - True if thie converter can convert from the provided type, false if not. + /// + /// The ITypeDescriptorContext for this call. + /// The Type being queried for support. + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); + } + + /// + /// CanConvertTo - Returns whether or not this class can convert to a given type. + /// + /// + /// bool - True if this converter can convert to the provided type, false if not. + /// + /// The ITypeDescriptorContext for this call. + /// The Type being queried for support. + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + return destinationType == typeof(string) || base.CanConvertTo(context, destinationType); + } + + /// + /// ConvertFrom - Attempt to convert to a RowDefinitionCollection from the given object. + /// + /// + /// The object which was constructoed. + /// + /// + /// An ArgumentNullException is thrown if the example object is null. + /// + /// + /// An ArgumentException is thrown if the object is not null and is not a valid type, + /// or if the destinationType isn't one of the valid destination types. + /// + /// The ITypeDescriptorContext for this call. + /// The CultureInfo which is respected when converting. + /// The Thickness to convert. + 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); + } + + /// + /// ConvertTo - Attempt to convert a RowDefinitionCollection to the given type + /// + /// + /// The object which was constructoed. + /// + /// + /// An ArgumentNullException is thrown if the example object is null. + /// + /// + /// An ArgumentException is thrown if the object is not null and is not a Thickness, + /// or if the destinationType isn't one of the valid destination types. + /// + /// The ITypeDescriptorContext for this call. + /// The CultureInfo which is respected when converting. + /// The RowDefintionCollection to convert. + /// The type to which to convert the RowDefintionCollection instance. + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string) && value is RowDefinitionCollection RowDefinitions) + { + var parts = new string[RowDefinitions.Count]; + + for (int i = 0; i < RowDefinitions.Count; i++) + { + parts[i] = RowDefinitions[i].Height.ToString(); + } + + return string.Join(",", parts); + } + + return base.ConvertTo(context, culture, value, destinationType); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs index c3fbb21309c..6491c897709 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs @@ -5111,14 +5111,18 @@ public partial class ColumnDefinitionCollectionConverter : System.ComponentModel { public ColumnDefinitionCollectionConverter() { } public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Type sourceType) { throw null; } + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { 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 bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { throw null; } public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.Globalization.CultureInfo cultureInfo, object source) { throw null; } + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { throw null; } } public partial class Grid : System.Windows.Controls.Panel, System.Windows.Markup.IAddChild From bcd9848ea80957960795f9415d05df71ba227d74 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Thu, 5 Sep 2024 18:57:33 +0530 Subject: [PATCH 5/6] Removing unnecessary changes --- .../System/Windows/Controls/Grid.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index a92678edba0..36249057481 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -36,7 +36,7 @@ #pragma warning disable 1634, 1691 // suppressing PreSharp warnings namespace System.Windows.Controls -{ +{ /// /// Grid /// @@ -270,6 +270,9 @@ public bool ShowGridLines set { SetValue(ShowGridLinesProperty, value); } } + /// + /// Returns a ColumnDefinitionCollection of column definitions. + /// [TypeConverter(typeof(ColumnDefinitionCollectionConverter))] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ColumnDefinitionCollection ColumnDefinitions @@ -302,6 +305,9 @@ public ColumnDefinitionCollection ColumnDefinitions } } + /// + /// Returns a RowDefinitionCollection of row definitions. + /// [TypeConverter(typeof(RowDefinitionCollectionConverter))] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RowDefinitionCollection RowDefinitions @@ -334,8 +340,6 @@ public RowDefinitionCollection RowDefinitions } } - - #endregion Public Properties //------------------------------------------------------ From 3add7830b88816b912dae34d2f6dc544baa72090 Mon Sep 17 00:00:00 2001 From: Himanshi Goyal Date: Mon, 9 Sep 2024 19:59:27 +0530 Subject: [PATCH 6/6] Resolving Comments --- .../ColumnDefinitionCollectionConverter.cs | 63 +++++++------------ .../System/Windows/Controls/Grid.cs | 46 ++++---------- .../RowDefinitionCollectionConverter.cs | 62 +++++++----------- .../Baml2006/WpfGeneratedKnownProperties.cs | 16 +---- 4 files changed, 57 insertions(+), 130 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs index 36a9b2d14e6..1ab3a411450 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ColumnDefinitionCollectionConverter.cs @@ -2,29 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -// -// -// Description: Contains the ColumnDefinitionCollectionConverter: TypeConverter for the ColumnDefinitionCollection. -// -// - -using MS.Internal; -using MS.Internal.Controls; -using MS.Internal.PresentationFramework; -using MS.Internal.Telemetry.PresentationFramework; -using MS.Utility; -using System; -using System.Collections; -using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; -using System.Windows.Threading; -using System.Threading; -using System.Windows; using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Media; using System.Windows.Markup; using System.Globalization; @@ -72,36 +51,38 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati /// /// An ArgumentNullException is thrown if the example object is null. /// - /// - /// An ArgumentException is thrown if the object is not null and is not a valid type, - /// or if the destinationType isn't one of the valid destination types. - /// /// The ITypeDescriptorContext for this call. /// The CultureInfo which is respected when converting. /// The Thickness to convert. public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - if (value is string input) + if(value != null) { - IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; - Grid grid = ipvt?.TargetObject as Grid; - if(grid != null) + if (value is string input) { - var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance - var converter = new GridLengthConverter(); - - foreach (var length in input.Split(',')) + IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; + Grid grid = ipvt?.TargetObject as Grid; + if(grid != null) { - if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + var collection = new ColumnDefinitionCollection(grid); // Pass Grid instance + var converter = new GridLengthConverter(); + + if(input == ""){ + return collection; + } + foreach (var length in input.Split(',')) { - collection.Add(new ColumnDefinition { Width = gridLength }); + if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + { + collection.Add(new ColumnDefinition { Width = gridLength }); + } } + return collection; } - return collection; } + return base.ConvertFrom(context, culture, value); } - - return base.ConvertFrom(context, culture, value); + throw GetConvertFromException(value); } /// @@ -113,16 +94,14 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c /// /// An ArgumentNullException is thrown if the example object is null. /// - /// - /// An ArgumentException is thrown if the object is not null and is not a Thickness, - /// or if the destinationType isn't one of the valid destination types. - /// /// The ITypeDescriptorContext for this call. /// The CultureInfo which is respected when converting. /// The ColumnDefintionCollection to convert. /// The type to which to convert the ColumnDefintionCollection instance. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { + ArgumentNullException.ThrowIfNull(value); + ArgumentNullException.ThrowIfNull(destinationType); if (destinationType == typeof(string) && value is ColumnDefinitionCollection columnDefinitions) { var parts = new string[columnDefinitions.Count]; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index 36249057481..f82a8920712 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -31,8 +31,6 @@ 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 @@ -279,12 +277,10 @@ 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 { @@ -292,16 +288,8 @@ public ColumnDefinitionCollection ColumnDefinitions _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); - } + _data ??= new ExtendedData(); + _data.ColumnDefinitions = value; } } @@ -314,12 +302,10 @@ 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 { @@ -327,16 +313,8 @@ public RowDefinitionCollection RowDefinitions _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); - } + _data ??= new ExtendedData(); + _data.RowDefinitions = value; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs index edff5c39645..7145712bfef 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/RowDefinitionCollectionConverter.cs @@ -2,29 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// -// -// -// Description: Contains the RowDefinitionCollectionConverter: TypeConverter for the RowDefinitionCollection. -// -// - -using MS.Internal; -using MS.Internal.Controls; -using MS.Internal.PresentationFramework; -using MS.Internal.Telemetry.PresentationFramework; -using MS.Utility; -using System; -using System.Collections; -using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; -using System.Windows.Threading; -using System.Threading; -using System.Windows; using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Media; using System.Windows.Markup; using System.Globalization; @@ -81,27 +60,32 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati /// The Thickness to convert. 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) + if(value != null){ + if (value is string input) { - var collection = new RowDefinitionCollection(grid); // Pass Grid instance - var converter = new GridLengthConverter(); - - foreach (var length in input.Split(',')) + IProvideValueTarget ipvt = context?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; + Grid grid = ipvt?.TargetObject as Grid; + if(grid != null) { - if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + var collection = new RowDefinitionCollection(grid); // Pass Grid instance + var converter = new GridLengthConverter(); + + if(input == ""){ + return collection; + } + foreach (var length in input.Split(',')) { - collection.Add(new RowDefinition { Height = gridLength }); + if (converter.ConvertFromString(length.Trim()) is GridLength gridLength) + { + collection.Add(new RowDefinition { Height = gridLength }); + } } + return collection; } - return collection; } - } - - return base.ConvertFrom(context, culture, value); + return base.ConvertFrom(context, culture, value); + } + throw GetConvertFromException(value); } /// @@ -113,16 +97,14 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c /// /// An ArgumentNullException is thrown if the example object is null. /// - /// - /// An ArgumentException is thrown if the object is not null and is not a Thickness, - /// or if the destinationType isn't one of the valid destination types. - /// /// The ITypeDescriptorContext for this call. /// The CultureInfo which is respected when converting. /// The RowDefintionCollection to convert. /// The type to which to convert the RowDefintionCollection instance. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { + ArgumentNullException.ThrowIfNull(value); + ArgumentNullException.ThrowIfNull(destinationType); if (destinationType == typeof(string) && value is RowDefinitionCollection RowDefinitions) { var parts = new string[RowDefinitions.Count]; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs index 93bcf0e4f1e..725e8523548 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfGeneratedKnownProperties.cs @@ -6403,13 +6403,7 @@ 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.SetDelegate = delegate(object target, object value) { ((System.Windows.Controls.Grid)target).ColumnDefinitions = (System.Windows.Controls.ColumnDefinitionCollection)value; }; bamlMember.IsWritePrivate = true; bamlMember.TypeConverterType = typeof(System.Windows.Controls.ColumnDefinitionCollectionConverter); bamlMember.Freeze(); @@ -6428,13 +6422,7 @@ 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.SetDelegate = delegate(object target, object value) { ((System.Windows.Controls.Grid)target).RowDefinitions = (System.Windows.Controls.RowDefinitionCollection)value; }; bamlMember.IsWritePrivate = true; bamlMember.TypeConverterType = typeof(System.Windows.Controls.RowDefinitionCollectionConverter); bamlMember.Freeze();