WPF水平对齐拉伸但不能将窗口宽度设置为100%

时间:2014-05-30 17:23:59

标签: wpf

我有一个简单的窗口,我希望有100%的宽度。我尝试了水平对齐的“拉伸”属性,但宽度仍然坚持到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" >

1 个答案:

答案 0 :(得分:1)

你好,你可以尝试一下:

的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" >

代码背后

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