4

User Interface Innovations With .NET 7

 1 year ago
source link: https://devm.io/dotnet/dot-net-windows-forms-wpf
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Windows Forms, WPF, and more

User Interface Innovations With .NET 7


Although Microsoft's GUI technologies are fortunately generally stable today, Microsoft found a way to add some additional user interface capabilities to the .NET Framework in version 7.

Hand on heart, especially senior developers — which I consider myself to be — ended up moving from the RAD capability included in Visual Basic to the .NET Framework. This article by no means covers all of the changes in .NET 7 related to GUI technologies. Instead, the goal is to provide a basic overview of what may be relevant in the world of .NET 7 innovations for user interface development.

Not killable: Windows Forms

If you're moving from Visual Basic 6 to .NET, you're probably using Windows Forms. It’s one of the oldest technologies in Microsoft's GUI system space, and still considered a full-fledged part of the ecosystem.

The theory that big tech behaves like a swarm, at least to a certain extent, is reinforced when reading the list of Windows Forms innovations. Microsoft focuses on giving users with limitations easier access to Windows Forms applications (similarities to Google’s App Dev Summit are purely coincidental).

For example, there are memory management corrections. Previously, when speech output (Narrator) was activated, control element corpses sometimes stayed in memory after the associated forms had long been cleared or closed.

Besides fixing these kinds of bugs, Microsoft retrofits additional triggers. The more precise the controls inform the Narrator application about events that occur, the more precise the voice assistance information will logically be.

In the context of these adjustments and improvements, Microsoft en passant used the opportunity to expand the in-house test solution UI Automation. The automated click unit tests it includes can now also address the following controls and interact with them:

  • TreeViewDateTimePicker
  • ToolStripContainer and ToolStripPanel
  • FlowLayoutPanel, TableLayoutPanel, and SplitContainer
  • PrintPreviewControl
  • WebBrowser

Another improvement concerns the increasingly common high-DPI monitors. The Windows Forms Engine can now automatically adapt forms and controls to the new operating state when an event of type WM_DPICHANGED occurs.

Here, scaling affects the controls as well as the MaximumSize and MinimumSize properties. This can lead to problems with already existing applications, which is why in .NET 7, using this function must be declared in the runtimeconfig.json file according to Listing 1’s scheme.

Listing 1

{
  "runtimeOptions": {
    "tfm": "net7.0",
    "frameworks": [
      ...
    ],
    "configProperties": {
      "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi": true,
    }
  }
}

Note that this declaration is only necessary in version 7. For version 8, Microsoft plans to reverse the behavior and enable the new logic by default. They will disable it only on explicit call from the developer in the runtimeconfig.json file.

Microsoft also tries to give Windows Forms users as many options as possible for furthering Windows development. Interestingly, they work together with external developers who — thanks to GitHub and open source — feel called upon to maintain parts of the product for self-fulfilment reasons. A good example of this is the CommonDialog, which now has the following additional features:

  • AddToRecent
  • CheckWriteAccess
  • ExpandedMode
  • OkRequiresInteraction
  • SelectReadOnly
  • ShowHiddenFiles
  • ShowPinnedPlaces
  • ShowPreview

For example, attributes like AddToRecent, allow you to decide if files selected in CommonDialog should be added to the operating system's Recents list. More information can be found in the GitHub issue available here, which also contains an extensive test program for demonstrating the functions.

The GitHub issue here is that Windows Form applications using the drag-and-drop system can display preview images with additional information about the planned operation.

Last but not least, Microsoft is also making changes in the area of data binding. The goal is to make it easier for Windows Forms developers to adopt the MVVM pattern, which is widely used in other parts of the ecosystem, into their intellectual property.

Several changes are required for this, which Microsoft describes in detail here. It should be noted that the new data binding interface in .NET 7.0 is still experimental and requires that you set the EnablePreviewFeatures attribute.

WPF - Reaching your goal with minor changes

The second Legacy GUI technology is WPF, which was introduced in .NET Framework 3.0. .NET 7.0 brings few changes in this area, but there aren’t really any new functions. Instead, maintenance is focused on improving performance. A good part of the GUI framework has been combed through — both by the community and by developers paid by Microsoft — in order to eliminate performance hogs.

In addition to dispensable allocations, Microsoft also handled cases where boxing or unboxing occurred unnecessarily. Modifying or destroying an object is an expensive operation that can quickly lead to unexpected, performance-intensive behavior, especially in a GUI stack (consider tables with nested layouts).

The other changes focus on accessibility. For example, there are now additional keyboard shortcuts in the data grid for adjusting the column width and activating sorting. Last but not least, some bugs have been fixed and additional test cases have been added to the automated testing suite. All in all...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK