I have a WPF app with multiple controls on each window, some overlayed etc, what i need is a way of getting the app to resize itself automatically depending on the screen re
The syntax Height="{Binding SystemParameters.PrimaryScreenHeight}" provides the clue but doesn't work as such. SystemParameters.PrimaryScreenHeight is static, hence you shall use:
And it would fit the whole screen. Yet, you may prefer to fit a percentage of the screen size, e.g. 90%, in which case the syntax must be amended with a converter in a binding spec:
Where RatioConverter is here declared in MyApp.Tools namespace as follows:
namespace MyApp.Tools {
[ValueConversion(typeof(string), typeof(string))]
public class RatioConverter : MarkupExtension, IValueConverter
{
private static RatioConverter _instance;
public RatioConverter() { }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ // do not let the culture default to local to prevent variable outcome re decimal syntax
double size = System.Convert.ToDouble(value) * System.Convert.ToDouble(parameter,CultureInfo.InvariantCulture);
return size.ToString( "G0", CultureInfo.InvariantCulture );
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ // read only converter...
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _instance ?? (_instance = new RatioConverter());
}
}
}
Where the definition of the converter shall inherit from MarkupExtension in order to be used directly in the root element without a former declaration as a resource.