WPF development, the use of System.Windows.SystemParameters get the screen resolution - ZDY 'LOVE | about photography, travel, outdoors, travel notes, Raiders, feelings, programming ...

Original: the development of WPF, using System.Windows.SystemParameters get the screen resolution - ZDY 'LOVE | about photography, travel, outdoors, travel notes, Raiders, feelings, programming ...

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

I like the WPF Window size settings:

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'}"

Wherein RatioConverter the codes are as follows:

[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();
    }
}

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12293243.html