简体   繁体   中英

WPF Horizontal alignement stretch but cannot set Window width to 100%

I have a simple Window that i would like to have a 100% width. I tried the "Stretch" property for Horizontal alignement but width is still stuck to 768.

<Window x:Class="WPF.View.MetroMsgBox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MetroMsgBox" ShowInTaskbar="True"
        WindowStyle="None" ResizeMode="NoResize" 
        FontFamily="Segoe UI" Background="{x:Null}"
        AllowsTransparency="True" 
        Height="135"  WindowStartupLocation="CenterScreen"
        Deactivated="MetroMsgBox_OnDeactivated" HorizontalAlignment="Stretch" >

Hi could you just try that :

Xaml

<Window x:Class="WPF.View.MetroMsgBox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MetroMsgBox" ShowInTaskbar="True"
        Name=_window
        WindowStyle="None" ResizeMode="NoResize" 
        FontFamily="Segoe UI" Background="{x:Null}"
        AllowsTransparency="True" 
        Height="135"  WindowStartupLocation="CenterScreen"
        Deactivated="MetroMsgBox_OnDeactivated" HorizontalAlignment="Stretch" >

Code Behind

InitializeComponent();
_window.Width = Screen.PrimaryScreen.Bounds.Width;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM