Wpf VirtualizingPanel停止ScrollViewer在Viewbox中的工作

Wpf VirtualizingPanel停止ScrollViewer在Viewbox中的工作,wpf,panel,virtualization,scrollviewer,viewbox,Wpf,Panel,Virtualization,Scrollviewer,Viewbox,我有一个简单的自定义面板,它位于ItemsControl的ItemsPanel中。ItemsControl的模板已更新,以使用查看框和滚动查看器包围itemsresenter。以下是XAML代码: <ItemsControl ItemsSource="{Binding Buttons, RelativeSource={RelativeSource AncestorType={x:Type Local:MainWindow}}}" ScrollViewer.Horizon

我有一个简单的自定义面板,它位于
ItemsControl
ItemsPanel
中。
ItemsControl
模板
已更新,以使用
查看框
滚动查看器
包围
itemsresenter
。以下是XAML代码:

<ItemsControl ItemsSource="{Binding Buttons, RelativeSource={RelativeSource 
    AncestorType={x:Type Local:MainWindow}}}" 
    ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
    ScrollViewer.VerticalScrollBarVisibility="Visible" 
    ScrollViewer.CanContentScroll="True">
    <ItemsControl.Template>
        <ControlTemplate TargetType="{x:Type ItemsControl}">
            <ScrollViewer CanContentScroll="True">
                <Viewbox Stretch="UniformToFill">
                    <ItemsPresenter />
                </Viewbox>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Local:TestPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Height="250" Width="250" HorizontalAlignment="Center" 
                Content="{Binding}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
最后,
MainWindow.xaml.cs

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        Buttons = new ObservableCollection<string>();
        IEnumerable<int> characterCodes = Enumerable.Range(65, 26);
        foreach (int characterCode in characterCodes) 
            Buttons.Add(((char)characterCode).ToString().ToUpper());
    }

    public static readonly DependencyProperty ButtonsProperty = 
        DependencyProperty.Register(nameof(Buttons), typeof(ObservableCollection<string>), 
        typeof(MainWindow), null);

    public ObservableCollection<string> Buttons
    {
        get { return (ObservableCollection<string>)GetValue(ButtonsProperty); }
        set { SetValue(ButtonsProperty, value); }
    }
}
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
按钮=新的ObservableCollection();
IEnumerable characterCodes=可枚举范围(65,26);
foreach(字符代码中的int字符代码)
添加(((char)characterCode.ToString().ToUpper());
}
公共静态只读从属属性按钮属性=
从属属性寄存器(按钮名称),类型(可观察采集),
typeof(主窗口),空);
公共可观察收集按钮
{
获取{return(observateCollection)GetValue(buttonProperty);}
set{SetValue(按钮属性,值);}
}
}
这一切都如期进行。。。到目前为止,一切顺利。问题是当我将基类从
面板
更改为
虚拟化面板
时,我需要这样做来虚拟化数据(不是这个示例按钮数据)。更改基类后,面板立即停止工作。我完全知道如何在面板中虚拟化数据。。。我有一个有效的例子。我的问题是,当我想在
ScrollViewer
中添加
Viewbox


请注意,此XAML在正常的
面板
堆栈面板
上可以正常工作,但一旦我将其更改为
virtualzingpanel
,它就会停止工作(不会呈现任何内容,
InternalChildren
属性不包含任何元素)。有人能帮我解释一下这个问题吗?

我仍然不知道为什么
virtualzingpanel
不能在
ScrollViewer
中的
ViewBox
中工作,但是我发现如果我扩展面板中的
virtualzingstackpanel
类,一切都会按预期工作

因此,对于那些需要堆叠虚拟化项目的人来说,解决方案是扩展
virtualzingstackpanel
类。对于那些需要其他类型的孩子安排的人,我很抱歉,但我没有答案,除非您删除
视图框

我仍然非常乐意收到关于这个问题的任何进一步信息

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        Buttons = new ObservableCollection<string>();
        IEnumerable<int> characterCodes = Enumerable.Range(65, 26);
        foreach (int characterCode in characterCodes) 
            Buttons.Add(((char)characterCode).ToString().ToUpper());
    }

    public static readonly DependencyProperty ButtonsProperty = 
        DependencyProperty.Register(nameof(Buttons), typeof(ObservableCollection<string>), 
        typeof(MainWindow), null);

    public ObservableCollection<string> Buttons
    {
        get { return (ObservableCollection<string>)GetValue(ButtonsProperty); }
        set { SetValue(ButtonsProperty, value); }
    }
}