//Get the working area width of the screen
double x = SystemParameters.WorkArea.Width;
//Get screen working area height
double y = SystemParameters.WorkArea.Height;
//Get the overall screen width
double x1= SystemParameters.PrimaryScreenWidth;
//Get the overall height of the screen
double y1 = SystemParameters.PrimaryScreenHeight;

My favorite WPF window size setting:

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

The implementation code of RatioConverter is 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();
    }
}

All Comments

Leave a Reply Cancel Reply

Tips: Your email address will not be disclosed!

If you can't see clearly,please click to change...