MainWindow NullReferenceException 문제 해결

개발 이야기/WPF 2016. 1. 13. 11:45

하위 레이아웃에서 최상위 윈도우의 크기가 필요할 경우가 있었다.

System.Windows.Application.Current.MainWindow 를 쓸 경우 NullReferenceException 발생 ㄷㄷ;


1
2
3
4
5
6
7
8
9
10
public MainWindow()
{
    this.Loaded += OnWindowLoad;
}
 
private void OnWindowLoad()
{
    Application.Current.MainWindow = this;
}
 
cs


저렇게 처리하면 NullReferenceException 문제 해결 완료!

윈도우 내 컨트롤을 다른 윈도우로 위치를 변경할 떄 주의할 점

개발 이야기/WPF 2016. 1. 13. 11:38

메인 윈도우 안에 어떤 컨트롤이 있다.

이 컨트롤을 다른 윈도우 창 내부에 위치시키도록 변경시키는 작업이 있었는데, 부모 자식 관계를 끊어줘야 한다고 한다.


이 방법이 맞는지는 모르겠지만,,,

1
2
3
4
5
6
7
8
Control control;
Window otherWindow;
 
Grid parent = (Grid)this;
parent.Children.Remove(control);
 
Grid child = (Grid)otherWindow.Content;
child.Children.Add(control);
cs

난 저렇게 했다.



'개발 이야기 > WPF' 카테고리의 다른 글

MainWindow NullReferenceException 문제 해결  (0) 2016.01.13