English 中文(简体)
WPF 窗口大小有监视器大小 [重复]
原标题:WPF Window size have monitor size [duplicate]

我是WPF的新人,我想做一个 最大尺寸(监测器尺寸)的窗口。

窗口 S XAML 代码是 :

<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 # 代码是 :

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

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

最佳回答

用于代码后方 :

a.WindowState = WindowState.Maximized;

从您的 XAML 中删除 SizeToContent

使用此代码 :

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

使用二次屏幕时会遇到不同分辨率的问题。

问题回答

above comment is working. i did below:- written in mainwindow.xaml.cs:-

public MainWindow()
        {
            this.WindowState = WindowState.Maximized;
            InitializeComponent();
        }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签