2015-12-30 53 views
0

以前我將ExpanderView從Windows Phone工具包移植到WinRT ExpanderRT,只是爲了現在注意到如果您在StackPanel或ListView中有兩個ExpanderView控件,並且希望第一個擴展視圖從頭開始展開通過將IsExpanded屬性設置爲True,第一個擴展器視圖將覆蓋第二個。ExpanderView不會從XAML內部擴展

下面是一個例子: -

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <StackPanel> 
     <local:ExpanderControl 
          IsExpanded="True" 
          Expander="This is the expander"> 
      <local:ExpanderControl.Items> 
       <Button Content="Yes"/> 
       <Button Content="No"/> 
      </local:ExpanderControl.Items> 
     </local:ExpanderControl> 
     <local:ExpanderControl 
          IsExpanded="False" 
          Expander="This is the expander"> 
      <ListViewItem> 
       <StackPanel Orientation="Horizontal"> 
        <Button Content="yes"/> 
        <Button Content="no"/> 
       </StackPanel> 
      </ListViewItem> 
     </local:ExpanderControl> 
    </StackPanel> 

</Grid> 

後幾個小時試圖調試ExpanderView控制代碼,我發現這個代碼被解僱4次

private void OnSizeChanged(object sender, SizeChangedEventArgs e) 
    { 
     if (_presenter == null) return; 
     var parent = _presenter.GetParentByType<ExpanderControl>(); 
     var gt = parent.TransformToVisual(_presenter); 
     var childToParentCoordinates = gt.TransformPoint(new Point(0, 0)); 
     _presenter.Width = parent.RenderSize.Width + childToParentCoordinates.X; 


    } 

    private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e) 
    { 
     if (null != _itemsCanvas && null != _presenter && IsExpanded) 
     { 
      _itemsCanvas.Height = _presenter.DesiredSize.Height; 
     } 
    } 

在第2次, _itemsCanvas的高度爲0.雖然第三次它的高度爲64,只是第四次覆蓋爲0。

我還沒有找到任何理由爲什麼發生這種情況。任何人都可以幫忙

+0

不是一個真正的答案,但我最近使用了這個擴展器:https://github.com/deanchalk/ExpanderUWP(沒有任何重疊),這裏是另一個https://github.com/JanJoris/Expander – Depechie

回答

0

從windows phone工具包移植Expander後,我遇到類似的問題。

要解決這個問題,我修改OnPresenterSizeChanged邏輯

private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e) 
    { 
     if (null != _itemsCanvas && null != _presenter && IsExpanded) 
     { 
      if (double.IsNaN(_itemsCanvas.Height)) 
      { 

       VisualStateManager.GoToState(this, CollapsedState, false); 
       UpdateVisualState(true); 
      } 
      else 
      { 
       // Already expanded, so we need to update the height of the canvas directly. 
       _itemsCanvas.Height = _presenter.DesiredSize.Height; 
      } 
     } 
    } 

什麼不同,這裏是我檢查項目帆布以前被渲染或不基於檢查,如果它的高度是楠,如果是這樣的大小寫然後我改變視覺狀態崩潰沒有過渡,然後我調用UpdateVisualState(true)。否則我只更新畫布的渲染高度。

問題是第一次調用UpdateVisualState時,內容預處理器爲null。