WPF 앱을 화면 중앙에 배치하는 방법은 무엇입니까?
시작시 기본 화면의 WPF 앱을 중앙에 배치하고 싶습니다. myWindow.Left 및 myWindow.Top을 설정해야한다는 것을 알고 있지만 값은 어디에서 얻을 수 있습니까?
나는 System.Windows.Forms.Screen.PrimaryScreen
분명히 WPF가 아닌 것을 발견했습니다 . 나에게 화면 해상도를 제공하는 WPF 대안이 있습니까?
이것을 창 생성자에 넣으십시오.
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
.NET FrameworkSupported in : 4, 3.5, 3.0
.NET Framework 클라이언트 프로필 지원 : 4, 3.5 SP1
xaml
WindowStartupLocation="CenterScreen"
WPF 앱에서 Screen 클래스를 계속 사용할 수 있습니다. 응용 프로그램에서 System.Windows.Forms 어셈블리를 참조하기 만하면됩니다. 이를 완료하면 (아래 예제에서는 System.Drawing을 참조) :
Rectangle workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
... 잘 작동합니다.
주 창 속성 WindowStartupLocation을 CenterScreen으로 설정하는 것을 고려 했습니까?
PresentationFramework의 SystemParameters 클래스는 어떻습니까? 그것은이 Workarea에의 당신을 위해 무엇을 찾고있는 것 같다 속성을.
그러나 Window.WindowStartupLocation 설정이 작동하지 않는 이유는 무엇입니까? CenterScreen은 열거 형 값 중 하나입니다. 센터링을 조정해야합니까?
System.Windows.Forms
애플리케이션 에서 어셈블리 를 참조 할 필요가 없습니다 . 대신 System.Windows.SystemParameters.WorkArea
. 이것은 System.Windows.Forms.Screen.PrimaryScreen.WorkingArea
!
WPF에 해당하는 것은 없습니다. System.Windows.Forms.Screen
NET 프레임 워크의 일부이며 WPF에서 사용할 수 있습니다.
자세한 내용은 이 질문 을 참조하세요.하지만 WindowInteropHelper
클래스를 사용 하여 WPF 컨트롤을 래핑 하여 화면과 관련된 호출을 사용할 수 있습니다 .
var window = new MyWindow();
화면 중앙 사용 :
window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
부모 창의 중앙에 사용 :
window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
참고 URL : https://stackoverflow.com/questions/935599/how-to-center-a-wpf-app-on-screen
'developer tip' 카테고리의 다른 글
입력 필드에 텍스트 추가 (0) | 2020.08.14 |
---|---|
Java의 이중 십진수 형식 (0) | 2020.08.14 |
서버 응답 헤더 IIS7 제거 (0) | 2020.08.14 |
OpenCV에서 Mat :: type ()을 사용하여 Mat 객체의 유형을 찾는 방법 (0) | 2020.08.14 |
"cordova build android"실행-android : fontVariationSettings 및 android : ttcIndex 속성을 찾을 수 없습니다. (0) | 2020.08.14 |