WPF窗口大小有监视器大小 [英] WPF Window size have monitor size

查看:74
本文介绍了WPF窗口大小有监视器大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF的新手,我想创建一个具有最大尺寸(监视器尺寸)的窗口.

I am new in WPF and I want to make a window that has max sizes (monitor sizes).

Window的XAML代码是这样的:

The Window's XAML code is this:

<Window x:Class="WpfApplication1.Stop"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Stop" Height="{Binding}" Width="{Binding}" Background="Black" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="260" d:DesignWidth="348" SizeToContent="WidthAndHeight">
    <Grid>
        <Button Content="Ok" Height="25" HorizontalAlignment="Left" Margin="194,36,0,0" Name="button1" VerticalAlignment="Top" Width="38" Click="button1_Click" />
        <TextBlock Height="17" HorizontalAlignment="Left" Margin="18,16,0,0" Name="textBlock1" Text="Introduceti parola:" VerticalAlignment="Top" Width="246" FontSize="14" Foreground="White" />
        <PasswordBox Height="25" HorizontalAlignment="Left" Margin="12,36,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="176" />
    </Grid>
</Window>

打开此窗口的C#代码是这样的:

The C# code that open this window is this:

Stop a = new Stop();                   
a.Show();
a.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
a.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

如何设置窗口大小来监视大小?

How can I set window size to monitor size?

推荐答案

在代码隐藏中使用此代码:

use this in code-behind:

a.WindowState = WindowState.Maximized;

,然后从XAML中删除SizeToContent.

使用以下代码:

a.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
a.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

使用分辨率不同的辅助屏幕时,您会遇到问题.

you will have problems when using secondary screen with different resolution.

这篇关于WPF窗口大小有监视器大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆