2012-06-01 3 views
0

다음 코드를 사용하여 팝업 창을 열 때 회색 조명 효과를 설정합니다. 그것은 잘 작동하지만 기본적으로 모든 컨트롤을 새로 고치거나 기본 창을 새로 고칩니다.wpf 팝업 윈도우 라이트 효과

특히이 라인 : currentWindow.Content = lightboxGrid;

Window currentWindow = Application.Current.Windows.Cast<Window>() 
    .SingleOrDefault(x => x.Name.Equals(MAIN_WINDOW_NAME)); 

Grid lightboxGrid = new Grid(); 
object currentWindowContent = currentWindow.Content; 
currentWindow.Content = null; 
lightboxGrid.Children.Add(new ContentControl() 
{ 
    Content = currentWindowContent 
}); 

// now add the grid that will "black out" the content 
Grid blackoutGrid = new Grid(); 
blackoutGrid.Background = new SolidColorBrush(Colors.Black); 
lightboxGrid.Children.Add(blackoutGrid); 
blackoutGrid.Opacity = 0.0; // start fully transparent 
blackoutGrid.Loaded += blackoutGrid_Loaded; 
currentWindow.Content = lightboxGrid; 
this._lightboxEffectApplied = true; 

은 무엇 메인 창을 새로 고치거나 컨트롤을 다시로드하지 않고 같은 효과를 할 수있는 옵션이 될 수 있을까?

enter image description here

답변

0

메인 창은 레이아웃의 루트로 그리드가있는 경우 (모든 콘텐츠는 첫 번째 셀에있는 경우에도), 당신은 그 그리드에 아이로서이 blackoutGrid을 추가 할 수 있으며 위의 표시 원래의 시각적 트리 구조를 어지럽히 지 않고 다른 요소들.

이 경우 창의 내용이 그리드가되고 그리드에 blackoutGrid를 추가하고 완료하면 제거 할 수 있습니다.

이 글을 쓰는 방법은 객체 지향 연습에 비해 약간의 것 같습니다. 기술적으로 라이트 박스 효과를 표시 할 수있는 메인 윈도우 여야합니다.