2011-04-14 4 views
0

MeasureOverrride가 작동하는 방식을 이해했다고 생각하지만 매우 간단한 경우에이를 사용하려고합니다. 작동하지 않습니다 ... 이제는 확신이 없습니다 ... Measureoverride를 사용한 후 Arrageoverride도 사용하거나 시스템이 나를 위해 그것을 할 것인가? 이 상황은 다음과 같습니다. Panel에서 상속받은 LinearLayout 클래스가 있고 wrapwidht 및 wrapheigh라는 두 개의 필드가 있습니다. LinearLayout의 너비 또는 높이가 참값 인 경우 자식이 필요로하는대로 필드가 있어야합니다. 그래서 어쩌면 내가 어떻게 작동하는지 이해하지 못했다 .. 내가 LinerLayout에 aading하고 아이들은 3 개 버튼은Silverlight에서 MeasureOverride는 어떻게 사용합니까?

protected override Size MeasureOverride(Size availableSize) { 

    Size panelDesiredSize = new Size(); 


    if ((this.widthWrap) || (this.heightWrap)) 
    { 

     foreach (UIElement elemento in this.Children) 
     { 

      System.Diagnostics.Debug.WriteLine(((FrameworkElement)elemento).DesiredSize.ToString()); 

      if (this.Orientation.Equals(System.Windows.Controls.Orientation.Vertical)) 
      { 
       if (this.widthWrap) 
       { 
        //the widest element will determine containers width 
        if (panelDesiredSize.Width < ((FrameworkElement)elemento).Width) 
         panelDesiredSize.Width = ((FrameworkElement)elemento).Width; 
       } 
       //the height of the Layout is determine by the sum of all the elment that it cointains 
       if (this.heightWrap) 
        panelDesiredSize.Height += ((FrameworkElement)elemento).Height; 
      } 
      else 
      { 
       if (this.heightWrap) 
       { 
        //The highest will determine the height of the Layout 
        if (panelDesiredSize.Height < ((FrameworkElement)elemento).Height) 
         panelDesiredSize.Height = ((FrameworkElement)elemento).Height; 
       } 

       //The width of the container is the sum of all the elements widths 
       if (this.widthWrap) 
        panelDesiredSize.Width += ((FrameworkElement)elemento).Width; 
      } 

     } 
    } 

    System.Diagnostics.Debug.WriteLine("desiredsizzeeeeeee" + panelDesiredSize); 

    return panelDesiredSize; 

} 

,하지만 아무것도 그려지지 않습니다 있습니다 .. panelDesiredSize가 제출 한 경우에도 올바른 : 그래서 내 Measureoveride처럼 보이는 아주 잘. 아무도 나를 아주 잘 도와 줄 수 있다면 :-)

답변

2

는 당신과 같은 이전의 게시물에 내 대답을 확인하십시오 Two Pass Layout system in WPF and Silverlight

대답없는 것을, 당신은 이 한 ArrangeOverride를 재정의을 가지고 있지 않지만, 사용하는 점은 무엇입니까 ArrangeOverride를 사용하지 않을 경우 MeasureOverride?

+0

당신 말이 맞아요.하지만 ArrangeOverride에 같은 코드를 씁니다. 아무 것도 일어나지 않습니다. 현재 요소의 크기를 설정하고 자식을 정렬하고 트리에 현재 요소를 추가한다고 가정합니다. 이 메서드는 현재 요소의 부모에 의해 호출됩니다. 언제 레이아웃 과정? 미안 해요, 많이 읽었지만 아무도 누가이 방법을 부르고 있는지 말하지 않습니다 ... 그리고 결과는 어떻게 될까요 ...... – Adriana

0

"요소"에서 측정을 호출해야합니다. 측정 중에는 Silverlight가 elemento의 템플릿에 선언 된 UI 요소를 만듭니다. 원하는 요소를 실제로 측정하고 필요하기 때문에 필요합니다. 그런 다음 elemento.DesiredSize.Width 및 Height를 사용하여 panelDesiredSize에 대해 원하는 크기를 표시해야합니다.

관련 문제