Wpf ItemsControl中ScrollViewer模板化项的零高度?

Wpf ItemsControl中ScrollViewer模板化项的零高度?,wpf,scrollviewer,itemscontrol,Wpf,Scrollviewer,Itemscontrol,我有一个带有任意项的ItemsControl。一些项目被包装在滚动查看器中。这些可滚动项目的代码利用视口宽度(几乎相当于实际宽度)和视口高度(几乎相当于实际高度)属性来排列/调整其视觉子项。只要我不将项目放在ItemsControl中,这就行了。当项目出现在ItemsControl中时,ViewportHeight的值等于0-有效地使我的项目不可见。请注意,我希望垂直排列项目,使所有项目的高度相等!没有花哨的东西,只有一个普通的堆叠面板 使用数据类型自动应用模板: <MyControl.R

我有一个带有任意项的
ItemsControl
。一些项目被包装在
滚动查看器
中。这些可滚动项目的代码利用
视口宽度
(几乎相当于
实际宽度
)和
视口高度
(几乎相当于
实际高度
)属性来排列/调整其视觉子项。只要我不将项目放在
ItemsControl
中,这就行了。当项目出现在
ItemsControl
中时,
ViewportHeight
的值等于0-有效地使我的项目不可见。请注意,我希望垂直排列项目,使所有项目的高度相等!没有花哨的东西,只有一个普通的
堆叠面板

使用
数据类型
自动应用模板:

<MyControl.Resources>
   <DataTemplate DataType="{x:Type MyScrollableItem}">
      <MyControlWrappedInScrollViewer Text="{Binding Text}" />
   </DataTemplate>
   <DataTemplate DataType="{x:Type MyItem}">
      <TextBlock Text="{Binding Text}"/>
   </DataTemplate>
</MyControl.Resources>
<ItemsControl ItemsSource="{Binding MyCollection}" />
为什么我的
ScrollViewer
的高度为0?我如何告诉我的
ItemsControl
适当调整项目大小?
例如,一个项目的高度等于ItemsControl高度。两个项目产生一半,依此类推。

这就成功了:

<Style TargetType="{x:Type ItemsControl}">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <UniformGrid Columns="1" IsItemsHost="True"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>

当您将ScrollViewer中的项目包装到具有ScrollViewer(ItemsControl)的项目中时,所有有趣的事情都可能发生;此外,它闻起来像是一个糟糕的设计决策,即这根本不是用户友好的。
<Style TargetType="{x:Type ItemsControl}">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <UniformGrid Columns="1" IsItemsHost="True"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>