상세 컨텐츠

본문 제목

[WPF] Designer 뷰에서와, 디버깅에서의 Height, Width 차이 해결하기

C#

by 경밤 2020. 11. 22. 22:49

본문

반응형

Designer 뷰에서와, 디버깅에서의 Height, Width 차이 해결하기


코딩을 하다 보면 가끔씩  디버깅했을때 프로그램의 크기가 디자인 뷰와 다르게 나타나 곤혹을 치를때가 많다.

이럴때 쉽고 간편하게 해결하는 방법이 있다. 만약, 그 프로그램이 크기에 관해서 정적이라면 안성맞춤인 해결법이다.

 

윈도우 xaml 코드를 잠깐 살펴보자. Window 태그의 Height, Width 프로퍼티를 설정했는데도 불구하고 예상과 다르게 움직인다. 이럴때, MinHeight와, MinWidth를 Height와 Width에 설정해놓았던 값과 동일 혹은, 원하는 값으로 설정하면 빌드하고 실행시, 예상대로 원하는 높이와 너비를 얻을 수 있다.

<Window x:Class="MyWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MyWPF"
        mc:Ignorable="d"
        Title="MainWindow" Height="700"  Width="500" MinWidth="500" MinHeight="700" SizeToContent="WidthAndHeight">
MinWidth="500" MinHeight="700" 

위 코드는 예시로 든 것이다. 만약 프로그램의 크기가 동적으로 바뀌어야한다면, 코드 내에서 MinWidth, MinHeight를 수시로 바꾸어 주면 된다.

반응형

관련글 더보기