2013-04-25 1 views
1

       는 I는 PopUp 내부 MediaElement 제어있다. MediaElement의 크기를 와이드 스크린으로 조정하면 하단의 영역이 잘립니다 (이미지 참조).WPF : PopUp의 MediaElement에서 화면 높이의 크기를 조정할 수없는 이유는 무엇입니까?         <img src="https://i.stack.imgur.com/b7dmx.png" alt="MediaElement"></p> <p>                           

내가 뭘 잘못 했니? 그것을 고치는 방법? 고마워요!

XAML :

<Popup PlacementRectangle="-500,0,0,0" Placement="Relative" IsOpen="True" Name="popup"> 
     <MediaElement Name="me" Width="480" Height="360" Volume="1" 
      MouseLeftButtonUp="me_MouseLeftButtonUp"/> 
    </Popup> 

코드 : 팝업 화면의 75 % 이상을 커버 할 수

bool fullscreen = false; 
    private void me_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
    { 
     fullscreen = !fullscreen; 
     if (fullscreen) 
     { 
      popup.PlacementRectangle = new Rect(0, 0, 0, 0); 
      popup.Placement = PlacementMode.Absolute; 
      me.Width = Screen.PrimaryScreen.Bounds.Width; 
      me.Height = Screen.PrimaryScreen.Bounds.Height; 
     } 
     else 
     { 
      popup.PlacementRectangle = new Rect(-500, 0, 0, 0); 
      popup.Placement = PlacementMode.Relative; 
      me.Width = 480; 
      me.Height = 360; 
     } 
    } 

답변

2

나는이 문제에 대한 해결 방법을 발견했다. PopupRoot 유형의 부모를 찾을 때까지 Popup의 하위 항목부터 시각적 트리를 검색하면됩니다. 너비와 높이를 원하는대로 설정할 수 있습니다. 나를 위해 일해 :

for (var parent = Child as FrameworkElement; parent != null; parent = VisualTreeHelper.GetParent(parent) as FrameworkElement) 
{ 
    if (parent.GetType().Name == "PopupRoot") 
    { 
     parent.Width = Target.ActualWidth; 
     parent.Height = Target.ActualHeight; 
     break; 
    } 
}