La sintaxis Altura = "{Binding} SystemParameters.PrimaryScreenHeight" proporciona la idea pero que no funciona como tal. SystemParameters.PrimaryScreenHeight es estático, por lo tanto, deberá utilizar:
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tools="clr-namespace:MyApp.Tools"
Height="{x:Static SystemParameters.PrimaryScreenHeight}"
Width="{x:Static SystemParameters.PrimaryScreenWidth}"
Title="{Binding Path=DisplayName}"
WindowStartupLocation="CenterScreen"
Icon="icon.ico"
>
y sería adaptarse a toda la pantalla. Sin embargo, es posible que prefiera ajustar un porcentaje del tamaño de la pantalla, p. 90%, en cuyo caso la sintaxis debe ser modificado con un convertidor en una especificación de unión:
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tools="clr-namespace:MyApp.Tools"
Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}, Converter={tools:RatioConverter}, ConverterParameter='0.9' }"
Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}, Converter={tools:RatioConverter}, ConverterParameter='0.9' }"
Title="{Binding Path=DisplayName}"
WindowStartupLocation="CenterScreen"
Icon="icon.ico"
>
¿Dónde está aquí RatioConverter declaró en MyApp.Tools espacio de nombres de la siguiente manera:
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());
}
}
}
Cuando la definición de el convertidor heredará de MarkupExtension para ser utilizado directamente en el elemento raíz sin una declaración anterior como recurso.
¿Por qué necesita esto? Si simplemente quiere cambiar el tamaño de la ventana, @Fischermaen le dio la respuesta. Pero si desea cambiar el tamaño de las fuentes, etc. Esto no es necesario, ya que WPF ya lo administra. Todas las representaciones de WPF funcionan en coordenadas virtuales, que se asignan a píxeles físicos de acuerdo con la configuración de DPI del sistema. –
¿Desea que su ventana sea exactamente del tamaño que su contenido desea? Lea esta [pregunta] similar (http://stackoverflow.com/questions/1746431/wpf-control-size-to-content) luego. – dowhilefor
pero mi wpf tiene conjuntos de cordinates y tamaños de fuentes, etc. Básicamente, el software necesita funcionar para diferentes resoluciones –