首页 > Windows开发 > 详细

开发 WPF 中,使用 System.Windows.SystemParameters 获得屏幕分辨率 - ZDY ‘ LOVE | 关于摄影、旅行、户外、游记、攻略、感想、编程...

时间:2020-02-11 00:36:05      阅读:261      评论:0      收藏:0      [点我收藏+]
原文:开发 WPF 中,使用 System.Windows.SystemParameters 获得屏幕分辨率 - ZDY ‘ LOVE | 关于摄影、旅行、户外、游记、攻略、感想、编程...

//得到屏幕工作区域宽度
double x = SystemParameters.WorkArea.Width;
//得到屏幕工作区域高度
double y = SystemParameters.WorkArea.Height;
//得到屏幕整体宽度
double x1= SystemParameters.PrimaryScreenWidth;
//得到屏幕整体高度
double y1 = SystemParameters.PrimaryScreenHeight;

我喜欢的 WPF Window 大小设置:

Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}, Converter={StaticResource RatioConverter}, ConverterParameter=‘0.8‘}" 
Width="{Binding RelativeSource={RelativeSource Self}, Path=Height, Converter={StaticResource RatioConverter}, ConverterParameter=‘1.6‘}"
MinHeight="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}, Converter={StaticResource RatioConverter}, ConverterParameter=‘0.5‘}"
MinWidth="{Binding RelativeSource={RelativeSource Self}, Path=MinHeight, Converter={StaticResource RatioConverter}, ConverterParameter=‘1.6‘}"

其中 RatioConverter 的实现代码如下:

[ValueConversion(typeof(string), typeof(string))]
public class RatioConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var size = 0d;
        if (value != null)
            size = System.Convert.ToDouble(value, CultureInfo.InvariantCulture) *
                   System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);

        return size;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

开发 WPF 中,使用 System.Windows.SystemParameters 获得屏幕分辨率 - ZDY ‘ LOVE | 关于摄影、旅行、户外、游记、攻略、感想、编程...

原文:https://www.cnblogs.com/lonelyxmas/p/12293243.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!