2013-10-29 79 views
0

我有一個WPF用戶控件包含ItemsControl與水平StackPanelItemsPanel(基本上某種WinRT集線器控制)。和內容擴展的用戶控件ScrollViewer更改內容大小(ItemControl),而不是顯示滾動條

大小如果我嘗試添加ScrollViewer在我ItemsControl,該ScrollViewerItemsControl使所有項目融入用戶控件範圍。

多數民衆贊成在某種程度上完全相反,我所期望的任何人都可以告訴我爲什麼scrollviewer這樣的行爲?

這裏是我的UserControl

<UserControl x:Class="ContentModule.ContentView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      xmlns:contentModule="clr-namespace:ContentModule" 
      xmlns:regions="http://www.codeplex.com/CompositeWPF" 
      xmlns:statics="clr-namespace:Infrastructure.Statics;assembly=Infrastructure" 
      d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance contentModule:ContentViewModel}" 
      VerticalAlignment="Top" HorizontalAlignment="Left"> 
     <ItemsControl regions:RegionManager.RegionName="{x:Static statics:ContentRegions.ContentCollection}"> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" /> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
     </ItemsControl> 
</UserControl> 

的項目是通過棱鏡RegionManager注射。

EDIT1:

UserControl是越來越注射到我的MainForm。它被分配到ContrentControl => ShellRegions.Content(第三個)

<Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <ContentControl Grid.Row="0" cal:RegionManager.RegionName="{x:Static statics:ShellRegions.MainMenu}" /> 
     <ItemsControl Grid.Row="1" cal:RegionManager.RegionName="{x:Static statics:ShellRegions.NavigationBar}" /> 
     <ContentControl Grid.Row="2" cal:RegionManager.RegionName="{x:Static statics:ShellRegions.Content}" /> 
    </Grid> 

編輯2: 一些更多細節。

ItemsControl樣子:this(灰色是UserControl,橙色都在ItemsControl項目) 改變Form/UserControl的界限時,如預期,但ItemsControl不顯示ScrollBar內容尺度。 如果我添加一個ScrollViewer,內容不會隨着邊界的變化進行縮放,而是垂直滾動而不是水平,或者它會根據ScrollBar屬性更改項目的寬度以適合UserControll

但我不能讓它工作,以保持縮放和滾動條添加到ItemsControl的底部。

+1

嗨,使用列表框。 :)爲什麼每個人都喜歡ItemsControl。其實很漂亮的轉儲。看到它不能虛擬化項目的事件,嘿嘿。 ListBix是真正的壞屁股。 –

+0

可以顯示用戶控件在窗口中的位置嗎? –

+0

@devhedgehog我試着改變它,但我不想要選擇我的項目,所以ListBox需要其他操作。我真的想留在ItemsControl中。 – Console

回答

0

一整天的研究後,我發現工作的解決方案:

<ItemsControl regions:RegionManager.RegionName="{x:Static statics:ContentRegions.ContentCollection}"> 
      <ItemsControl.Template> 
       <ControlTemplate> 
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled"> 
         <ItemsPresenter/> 
        </ScrollViewer> 
       </ControlTemplate> 
      </ItemsControl.Template> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" /> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
     </ItemsControl> 
0

你可以嘗試做如下:

裹在一個ScrollViewer中的控制和設置CanContentScrol屬性爲true。

更多更改您的ItemsControl面板爲VirtualizingStackPanel。

<ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <VirtualizingStackPanel Orientation="Horizontal" /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 

告訴我們它是否奏效,或者這些變化會帶來什麼樣的新問題。

+0

不幸的是,這並不能幫助我或者添加詳細的描述 – Console

+0

我看不到你的ScrollViewer。它在哪裏? –

相關問題