Skip to content

[Breaking change]: Removed the DefaultValueAttribute from properties that need dynamically calculated default values. #33954

Closed

Description

@Tanya-Solyanik

Description

We are removing DefaultValueAttribute from control properties that are dependent on the default font height.

Version

.NET 8 Preview 2

Previous behavior

Default values were hardcoded according to an assumed application wide font.

New behavior

Design time default values are calculated at the start up based on the current font metrics.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

This attribute is designed to define constant default values used by the WinForms designer. In the past this DefaultValueAttribute had been used to specify defaults on certain properties that depend on the current font height. When we set a new default font in .NET Core 3.1, we had not updated the attribute values accordingly. Moreover, we now have an API to modify application font. Thus, it makes sense to use dynamic default values instead of the constant ones. Designer provides alternative methods to specify dynamic default values. However, for properties decorated with this attribute, designer would not attempt the alternatives and would use the constant default value instead. The alternative method preserves design time functionality provided by this attribute.

Recommended action

DefaultValueAttribute is intended for internal use in design time scenarios in. It should be avoided in other scenarios.

Feature area

Windows Forms

Affected APIs

ListBox.ItemHeight - Preview 2
DataGridViewRow.Height - Preview 2

and more properties will be added later to this list, this is work in progress.


Associated WorkItem - 63470

Activity

  1. added
    breaking-change
    on Feb 10, 2023
  2. added
    🏁 Release: .NET 8
    and removed
    ⌚ Not Triaged
    on Feb 10, 2023
  3. added
    🗺️ reQUEST
    on Feb 10, 2023
  4. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Feb 10, 2023
  5. moved this from ✅ Done to 🏗 In progress in dotnet/docs March 2023 sprinton Feb 24, 2023
  6. moved this from 🏗 In progress to 🔖 Ready in dotnet/docs March 2023 sprinton Feb 27, 2023
  7. moved this from 🔖 Ready to 🏗 In progress in dotnet/docs March 2023 sprinton Mar 14, 2023
  8. moved this from 🏗 In progress to ✅ Done in dotnet/docs March 2023 sprinton Mar 31, 2023
  9. moved this from 🆕 New to ✅ Done in .NET 8.0 work itemson Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8📌 seQUESTeredbreaking-change

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions