0

我有一个 WPF UserControl,其中包含一个ItemsControlHorizo ​​ntal StackPanelas ItemsPanel(基本上是某种 WinRT Hub 控件)。并且内容扩展了 UserControl 的大小

如果我尝试ScrollViewer在我的 周围添加一个ItemsControl,则ScrollViewer缩小ItemsControl所有项目都适合 UserControl 边界。

这与我的预期完全相反,有人能告诉我为什么滚动查看器会这样吗?

这是我的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>

项目通过 Prism RegionManager 注入。

编辑1:

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/的边界时缩放,但不显示 a 。如果我添加一个内容不再随着边界的变化而缩放,并且可以垂直滚动而不是水平滚动,或者它确实会改变项目的宽度以适应取决于属性。UserControlItemsControlScrollBarScrollViewerUserControllScrollBar

但我无法让它保持缩放并将滚动条添加到ItemsControl.

4

2 回答 2

0

您可以尝试执行以下操作:

将控件包装在 ScrollViewer 中并将 CanContentScroll 属性设置为 TRUE。

此外,将 ItemsControl 的 Panel 更改为 VirtualizingStackPanel。

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

告诉我们它是否有效,或者这些变化会带来什么样的新问题。

于 2013-10-30T08:38:59.470 回答
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>
于 2013-10-30T14:23:27.177 回答