我有一個WPF用戶控件包含ItemsControl
與水平StackPanel
ItemsPanel
(基本上某種WinRT集線器控制)。和內容擴展的用戶控件ScrollViewer更改內容大小(ItemControl),而不是顯示滾動條
大小如果我嘗試添加ScrollViewer
在我ItemsControl
,該ScrollViewer
縮ItemsControl
使所有項目融入用戶控件範圍。
多數民衆贊成在某種程度上完全相反,我所期望的任何人都可以告訴我爲什麼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
樣子:(灰色是UserControl
,橙色都在ItemsControl
項目) 改變Form
/UserControl
的界限時,如預期,但ItemsControl
不顯示ScrollBar
內容尺度。 如果我添加一個ScrollViewer
,內容不會隨着邊界的變化進行縮放,而是垂直滾動而不是水平,或者它會根據ScrollBar
屬性更改項目的寬度以適合UserControll
。
但我不能讓它工作,以保持縮放和滾動條添加到ItemsControl
的底部。
嗨,使用列表框。 :)爲什麼每個人都喜歡ItemsControl。其實很漂亮的轉儲。看到它不能虛擬化項目的事件,嘿嘿。 ListBix是真正的壞屁股。 –
可以顯示用戶控件在窗口中的位置嗎? –
@devhedgehog我試着改變它,但我不想要選擇我的項目,所以ListBox需要其他操作。我真的想留在ItemsControl中。 – Console