【问题标题】:WPF, making scrollviewer work with stackpanel programaticallyWPF,使scrollviewer以编程方式与stackpanel一起工作
【发布时间】:2016-03-10 16:06:34
【问题描述】:

我想在堆栈面板中添加一个滚动查看器,以便我可以随着堆栈面板的内容上下移动。

我见过的所有解决方案都是使用 XAML,我不想使用 XAML,我只想使用 C#。

我写了这个:

                    _projectsPanel = new StackPanel();
                    _projectsPanel.Height = 100;
                    _navigationPanel = new ScrollViewer();
                    _navigationPanel.Content = _projectsPanel;

这段代码在堆栈面板旁边添加了一个滚动查看器(好的),但是箭头按钮被锁定,我不能向下或向上。

提前致谢。

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    如果StackPanelScrollViewer 小,则滚动条默认为禁用状态。

    您只需要更改ScrollViewer 和/或StackPanel 的大小,因此StackPanel 的高度大于ScrollViewer 的高度

    【讨论】:

    • 你刚刚救了我的命。谢谢。
    【解决方案2】:

    确保内容大于 100 像素的堆栈面板以启用滚动条按钮,然后设置 ScrollbarVisibility 属性

    //Use Visible or Auto Enum based on your requirement.
    //Visibile to show always and Auto only if its required
    _navigationPanel.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
    

    【讨论】:

    • 只需将滚动查看器高度设置为小于堆栈面板高度的值就可以了。不过还是谢谢。
    【解决方案3】:

    设置高度 ScrollViewer _navigationPanel

    _projectsPanel = new StackPanel();
    _navigationPanel = new ScrollViewer();
    _navigationPanel.Height = 100;
    _navigationPanel.Content = _projectsPanel;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多