Skip to content

Commit ffeaae5

Browse files
CommandParameter property: Provide designer support and control CodeDOM serialization (#13802)
Fixes #13801. Affected Controls are - `ButtonBase` - `ToolStripItem` Fixes: - `CommandParameter` is now shown in the property browser, and string values can be directly entered. - If `CommandParameter` is effectively of type `string`, the values are getting CodeDOM-serialized and -deseriaslized. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/13802)
2 parents 3c5b282 + 7a5a20a commit ffeaae5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,9 @@ public event EventHandler? CommandChanged
221221
/// which is assigned to the <see cref="Command"/> property.
222222
/// </summary>
223223
[Bindable(true)]
224-
[Browsable(false)]
225-
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
226224
[SRCategory(nameof(SR.CatData))]
227225
[SRDescription(nameof(SR.CommandComponentCommandParameterDescr))]
226+
[TypeConverter(typeof(StringConverter))]
228227
public object? CommandParameter
229228
{
230229
get => _commandParameter;
@@ -238,6 +237,12 @@ public object? CommandParameter
238237
}
239238
}
240239

240+
private void ResetCommandParameter() => CommandParameter = null;
241+
242+
private bool ShouldSerializeCommandParameter() =>
243+
_commandParameter is string parameter
244+
&& !string.IsNullOrEmpty(parameter);
245+
241246
/// <summary>
242247
/// Occurs when the value of the <see cref="CommandParameter"/> property has changed.
243248
/// </summary>

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripItem.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,9 @@ public event EventHandler? CommandChanged
442442
/// which is assigned to the <see cref="Command"/> property.
443443
/// </summary>
444444
[Bindable(true)]
445-
[Browsable(false)]
446-
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
447445
[SRCategory(nameof(SR.CatData))]
448446
[SRDescription(nameof(SR.CommandComponentCommandParameterDescr))]
447+
[TypeConverter(typeof(StringConverter))]
449448
public object? CommandParameter
450449
{
451450
get => _commandParameter;
@@ -460,6 +459,12 @@ public object? CommandParameter
460459
}
461460
}
462461

462+
private void ResetCommandParameter() => CommandParameter = null;
463+
464+
private bool ShouldSerializeCommandParameter() =>
465+
_commandParameter is string parameter
466+
&& !string.IsNullOrEmpty(parameter);
467+
463468
/// <summary>
464469
/// Occurs when the value of the <see cref="CommandParameter"/> property has changed.
465470
/// </summary>

src/test/unit/System.Windows.Forms/System/Windows/Forms/BinaryFormat/WinFormsBinaryFormattedObjectTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.ComponentModel;
@@ -270,9 +270,9 @@ public void Control_BinaryFormatted_DesignerVisibleProperties(object value, stri
270270
{
271271
{ new Control(), new string[] { "DataContext: Object", "Tag: Object" } },
272272
{ new Form(), new string[] { "DataContext: Object", "Tag: Object" } },
273-
{ new Button(), new string[] { "DataContext: Object", "Tag: Object" } },
274-
{ new CheckBox(), new string[] { "DataContext: Object", "Tag: Object" } },
275-
{ new RadioButton(), new string[] { "DataContext: Object", "Tag: Object" } },
273+
{ new Button(), new string[] { "CommandParameter: Object", "DataContext: Object", "Tag: Object" } },
274+
{ new CheckBox(), new string[] { "CommandParameter: Object", "DataContext: Object", "Tag: Object" } },
275+
{ new RadioButton(), new string[] { "CommandParameter: Object", "DataContext: Object", "Tag: Object" } },
276276
{ new DataGridView(), new string[] { "DataSource: Object", "DataContext: Object", "Tag: Object" } },
277277
{ new DateTimePicker(), new string[] { "DataContext: Object", "Tag: Object" } },
278278
{ new GroupBox(), new string[] { "DataContext: Object", "Tag: Object" } },

0 commit comments

Comments
 (0)