본문 바로가기
프로그래밍/UWP | WPF

[UWP] 프로그램 실행 시 화면의 크기를 최대화하는 방법

by 남생 namsaeng 2022. 8. 11.
반응형
  • 프로그램을 작성하여 운용할 때 실행창을 곧바로 최대화해야 할 상황이 올 수 있다.

 

<MainPage.xaml.cs>

namespace TestProject
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            MaximizePageOnLoad();
            this.InitializeComponent();
        }

        void MaximizePageOnLoad()
        {
            var page = DisplayInformation.GetForCurrentView();

            // 화면 해상도를 얻어온다
            var page_resolution = new Size(page.ScreenWidthInRawPixels, page.ScreenHeightInRawPixels);

            // 유효한 픽셀단위로 화면 크기를 계산한다..
            var page_scale = page.ResolutionScale == ResolutionScale.Invalid ? 1 : page.RawPixelsPerViewPixel;
            var page_bounds = new Size(page_resolution.Width / page_scale, page_resolution.Height / page_scale);

            ApplicationView.PreferredLaunchViewSize = new Size(page_bounds.Width, page_bounds.Height);
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;
        }
    }
}

 

<MainPage.xaml.cs>

<Page
    x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestProject"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Grid.Row="0" Grid.Column="0">
            <TextBlock Text="U" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="0" Grid.Column="1">
            <TextBlock Text="W" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="0" Grid.Column="2">
            <TextBlock Text="P" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="1" Grid.ColumnSpan="3">
            <TextBlock Text="Screen" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="2" Grid.Column="0">
            <TextBlock Text="MAXI" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="2" Grid.Column="1">
            <TextBlock Text="MIZE" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
        <Border Grid.Row="2" Grid.Column="2">
            <TextBlock Text=":D" FontSize="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
    </Grid>
</Page>

 

Maximize UWP Screen
Maximize UWP Screen

 

반응형

댓글