Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从可移植类库中获取屏幕大小?_C#_.net_Portable Class Library - Fatal编程技术网

C# 如何从可移植类库中获取屏幕大小?

C# 如何从可移植类库中获取屏幕大小?,c#,.net,portable-class-library,C#,.net,Portable Class Library,因此,在普通的.net程序集中,我可以访问SystemInformation.VirtualScreen。如何在PCL中实现这一点?这就是我要做的: 在PCL项目中引入IVirtualScreen的抽象 在桌面类库(参考PCL项目)中,提供一个适配器类,以将SystemInformation.VirtualScreen映射到IVirtualScreen界面 在引导桌面应用程序时,请向IoC容器注册特定于平台的版本 // in your PCL project public interface I

因此,在普通的.net程序集中,我可以访问
SystemInformation.VirtualScreen
。如何在PCL中实现这一点?

这就是我要做的:

  • 在PCL项目中引入
    IVirtualScreen
    的抽象
  • 在桌面类库(参考PCL项目)中,提供一个适配器类,以将
    SystemInformation.VirtualScreen
    映射到IVirtualScreen界面
  • 在引导桌面应用程序时,请向IoC容器注册特定于平台的版本

    // in your PCL project
    public interface IVirtualScreen {
         Rectangle Current { get; 
    }
    
    
    // in your desktop project
    public interface DesktopScreen : IVirtualScreen {
       public Rectangle Current { 
         get {
            return System.Windows.Forms.SystemInformation.VirtualScreen;
       }
    }
    
  • 但这回避了一个问题:这是你在PCL项目中需要的东西吗


    由于UI技术(WinForms/WPF/SL/WP7/WP8/WinRT)之间的根本区别,您最终可能会做很多特定于平台的事情,虽然您可以为移动应用程序插入不同的IVirtualScreen实现,但这样做有价值吗?

    创建这样的抽象通常是正确的想法。但是,在这种情况下,我想知道为什么需要在便携库中获取当前屏幕大小。没有任何与UI相关的东西是真正可移植的,因此我不希望需要知道屏幕大小的代码通常会放在可移植库中。另外,矩形类型也是不可移植的,所以你需要为它创建自己的类型。但不管怎样,你都能得到图片…如果可能的话,如果你真的需要PCL,我更愿意将宽度和高度作为参数传递。越简单越好。