System.Windows.Forms 库的替代方案是什么,因为该库在 .Net7.0 中不提供跨平台

问题描述 投票:0回答:1

我在 .Net Framework 项目中使用了 Syetem.Windows.Forms 库,但现在我已将其迁移到 .Net7.0,现在“System.Windows.Forms”在 .net7.0 中不可用。 因为我想让我的项目兼容跨平台,所以我不想在我的 .csproj 文件中添加此属性 -

 <UseWindowsForms>true</UseWindowsForms>
 <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>

这将使其仅适用于特定于窗口的项目。

下面是代码,我在其中使用 Window.Form 库 PropertyTab 类并重写 Bitmap、TagName、GetProperties 属性和方法。

using System;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.ComponentModel;
using System.Windows.Forms.Design;

namespace MARKEM.LocalisationServices
{
    /// <summary>
    /// LocalisedPropertyTab inherits from PropertyTab so to allow customization of 
    /// the properties displayed in the PropertyGrid.
    /// </summary>
    public class LocalisedPropertyTab : PropertyTab
    {

        /// <summary>
        /// The Property Tab's display name.
        /// </summary>
        private string m_tabName;

        /// <summary>
        /// Constructs a new PropertyTab with a specified display name.
        /// </summary>
        /// <param name="tabName">Name of the PropertyTab.</param>
        public LocalisedPropertyTab(string tabName) : base()
        {
            m_tabName = tabName;
        }

        /// <summary>
        /// Get the name of the tab.
        /// </summary>
        public override string TabName {
            get {
                return m_tabName;
            }
        }

        /// <summary>
        /// Get a Bitmap for the Tab.
        /// Currently returns an empty 16x16 bitmap as we don't need a visual display
        /// when there is only one tab.
        /// </summary>
        public override Bitmap Bitmap {
            get {
                return new Bitmap(16,16);
            }
        }

        public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attrs) {
                     //Removed the code
            } 

    }//end of class
}//end of namespace

微软是否提供任何替代库来代替 System.Windows.Forms

检查替代方案,仍然没有找到任何解决方案。

cross-platform entity-framework-migrations .net-7.0 .net-4.8
1个回答
0
投票

这里唯一的答案是:

System.Windows.Forms
没有跨平台的替代方案。正如其名称所示,它适用于 Windows。

即使您有一个不是 WinForms 可执行文件但确实引用了

System.Windows.Forms
的类库,也不可能使该库跨平台。您使用的类,
PropertyTab
,是一个仅限 WinForms 的类,因此本质上不是跨平台的。

对于跨平台 UI 开发,您必须使用跨平台框架,例如 MauiFlutter 等。

© www.soinside.com 2019 - 2024. All rights reserved.