2012-06-18 66 views
3

我在一個ScrollViewer中的內部應用程序啓用捕捉點,在這個問題描述:Enabling ScrollViewer HorizontalSnapPoints with bindable collection捕捉的ScrollViewer在Windows 8 Metro在寬屏幕沒有捕捉到最後一項

是我遇到的問題是,我正在嘗試我的應用程序在全高清顯示器(1920x1080),每個項目是1400像素寬度。當我在項目#n-1中滾動滾動時,我無法滾動到最後一個,因爲它不會捕捉到...

我必須做的破解是添加一個「假」項,透明底,這樣我就可以滾動到我的收藏的最後一個項目:

<Page.Resources> 
    <Style x:Key="ItemsControlStyle" TargetType="ItemsControl"> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate> 
       <VirtualizingStackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ItemsControl"> 
       <ScrollViewer Style="{StaticResource HorizontalScrollViewerStyle}" HorizontalSnapPointsType="Mandatory" HorizontalSnapPointsAlignment="Near"> 
        <ItemsPresenter /> 
       </ScrollViewer> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    </Style> 
</Page.Resources> 

<ItemsControl Style="{StaticResource ItemsControlStyle}"> 
    <Border Background="Red" Height="1000" Width="1400"/> 
    <Border Background="Blue" Height="1000" Width="1400"/> 
    <Border Background="Green" Height="1000" Width="1400"/> 
    <Border Background="Yellow" Height="1000" Width="1400"/> 
    <Border Background="Magenta" Height="1000" Width="1400"/> 
    <Border Background="Transparent" Height="1000" Width="1000" /> 
</ItemsControl> 

,我不得不即使使用此技巧的第二個問題,是從metro應用我不」無法訪問屏幕大小,所以我甚至無法添加具有可變寬度的最後一項,具體取決於屏幕以解決此問題。有什麼建議麼?

謝謝!

回答

1

看來,以編程方式更改最後一項的寬度是最好的解決方案,使用Window.Current.Bounds.Width;

+0

您如何找到更好的解決方案?當你的意思是改變寬度時,它是否真的使最後一個項目看起來比其他項目更小? –

0

我發現,你可以從內部LayoutAwarePage.cs使用WindowSizeChanged事件(e.Size

這就是說訪問當前的屏幕大小,我敢肯定,有可能是訪問該事件的更好的方法。

+0

是,使用Window.Current.Bounds;但仍然不是理想的解決方案。 –

0

之前提供的解決方案僅適用於少量情況(具有固定尺寸的項目)並且存在視覺問題。

UPDATE: 見例如需要在這裏Enabling ScrollViewer HorizontalSnapPoints with bindable collection

沒有「假」項,第二:你不需要屏幕尺寸只是ItemsPresenter.Parent.ActualHeight(或寬度,這取決於使用方向列表)和項目容器寬度 - 請參閱示例。

0

chuanged Horizo​​ntalSnapPointsAlignment時ViewChanging,像這樣:

private void sv_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e) 
    { 
     if (e.NextView.HorizontalOffset <e.FinalView.HorizontalOffset) 
     { 
      sv.HorizontalSnapPointsAlignment = SnapPointsAlignment.Far; 
     } 
     else if (e.NextView.HorizontalOffset > e.FinalView.HorizontalOffset) 
     { 
      sv.HorizontalSnapPointsAlignment = SnapPointsAlignment.Near; 
     } 
    }