2010-12-30 4 views
1

다른 AppDomain에서 INativeHandleContract를 통해 UI 컨트롤 중 하나를 가져 오는 응용 프로그램이 있습니다. 컨트롤의 크기가 변경되면 호스트의 FrameworkElement에 업데이트 된 크기가 적용되지 않습니다. 이 문제를 해결할 방법이 있는지 궁금합니다. 당신이 확장 확장기를 축소로WPF UI AddIn이 원하는 크기를 업데이트하지 않습니다.

public partial class Window1 : Window 
{ 
    private StackPanel m_stackPanel; 
    private Expander m_expander; 

    private UIElement m_expanderAddIn; 

    public Window1() 
    { 
     InitializeComponent(); 

     m_stackPanel = new StackPanel { Orientation = Orientation.Vertical }; 
     m_stackPanel.Background = Brushes.Red; 
     m_expander = new Expander 
         { 
          ExpandDirection = ExpandDirection.Right, 
          Background=Brushes.Blue, 
          IsExpanded=true, 
         }; 
     m_expander.Expanded += CheckStuff; 
     m_expander.Collapsed += CheckStuff; 

     Rectangle r = new Rectangle {Fill = Brushes.LightGray, Height = 300, Width = 300}; 

     m_expander.Content = r; 

     m_expanderAddIn = FrameworkElementAdapters.ContractToViewAdapter(FrameworkElementAdapters.ViewToContractAdapter(m_expander)); 

     m_stackPanel.Children.Add(m_expanderAddIn); 

     Content = m_stackPanel; 
    } 

    private void CheckStuff(object sender, RoutedEventArgs e) 
    { 
     Debug.WriteLine("Expander: " + m_expander.DesiredSize); 
     Debug.WriteLine("Add in: " + m_expanderAddIn.DesiredSize); 
     Debug.WriteLine("Stack Panel: " + m_stackPanel.DesiredSize); 
    } 
} 

당신이 StackPanel에의 높이가 변화 기대하지만, 그렇지 않습니다 :

다음 샘플 코드합니다 (XAML 그냥 빈 창입니다)입니다. 어떤 아이디어라도 유용 할 것입니다. 감사합니다.

답변

0

정말 이상해. 왜 그렇게 행동하는지 모르겠다. 이것은 아마 여러분의 문제를 재현하는 작은 예일 뿐이므로 어쩌면 이것이별로 도움이되지는 않을 것이지만 나는 여러분의 모범을 3 가지 변화와 함께 일하고있다.

  1. "더미"StackPanel에서 확장기를 감싸고 대신 m_expanderAddIn의 루트 요소로 사용하십시오. Expander의 Height 문제를 해결했습니다.
  2. 변경 m_expander의의 ActualHeight에
  3. 바인드 m_expanderAddIn의 높이를 FrameworkElement하는 UIElement에서 m_expanderAddIn의 유형

코드

public partial class Window1 : Window 
{ 
    private StackPanel m_stackPanel; 
    private Expander m_expander; 

    private FrameworkElement m_expanderAddIn; 

    public Window1() 
    { 
     InitializeComponent(); 

     m_stackPanel = new StackPanel { Orientation = Orientation.Vertical }; 
     m_stackPanel.Background = Brushes.Red; 
     m_expander = new Expander 
         { 
          ExpandDirection = ExpandDirection.Right, 
          Background=Brushes.Blue, 
          IsExpanded=true, 
         }; 
     m_expander.Expanded += CheckStuff; 
     m_expander.Collapsed += CheckStuff; 

     Rectangle r = new Rectangle {Fill = Brushes.LightGray, Height = 300, Width = 300}; 

     m_expander.Content = r; 
     StackPanel stackPanel = new StackPanel(); 
     stackPanel.Children.Add(m_expander); 

     m_expanderAddIn = FrameworkElementAdapters.ContractToViewAdapter(FrameworkElementAdapters.ViewToContractAdapter(stackPanel)); 

     Binding binding = new Binding("ActualHeight"); 
     binding.Source = m_expander; 
     m_expanderAddIn.SetBinding(FrameworkElement.HeightProperty, binding); 

     m_stackPanel.Children.Add(m_expanderAddIn); 

     Content = m_stackPanel; 
    } 

    private void CheckStuff(object sender, RoutedEventArgs e) 
    { 
     Debug.WriteLine("Expander: " + m_expander.DesiredSize); 
     Debug.WriteLine("Add in: " + m_expanderAddIn.DesiredSize); 
     Debug.WriteLine("Stack Panel: " + m_stackPanel.DesiredSize); 
    } 
} 
+0

나중에 불행하게도이 풀 스케일에 대해 작동하지 않습니다 우리 문제의 버전. 하지만 해결책은 인상적입니다. 해결해 주셔서 감사합니다. –

관련 문제