ScrollViewer不起作用 [英] ScrollViewer does not work

查看:47
本文介绍了ScrollViewer不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经创建了ScrollViewer,如下所示,但是当堆栈面板仅包含子对象时,即使高度很高,它也不会显示滚动条.但是,当堆栈面板有多个子代时,将显示滚动条.

Hi All,

I have created the ScrollViewer as like the below , But it does not show the scroll bar while the stackpanel contains only on child, even the height is very high. But the scroll will be show while the stackpanel has more than one child.

<Window x:Class="ScrollViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ScrollViewer" WindowState="Maximized"
        mc:Ignorable="d" HorizontalContentAlignment="Left"
        Title="MainWindow" >
    <ScrollViewer  Name="ScrollViewer1"  VerticalScrollBarVisibility="Auto" Width="1342" HorizontalScrollBarVisibility="Auto" HorizontalContentAlignment="Left" VerticalAlignment="Top"  CanContentScroll="True">
        <StackPanel Name="maindynamicStkPnl"  HorizontalAlignment="Left" IsEnabled="False" Height="330"  ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
            <TextBox Height="1200" Text="Sowndaiyan"/>
            <!--<TextBox Height="1200" Text="Sowndaiyan"/>-->
        </StackPanel>
    </ScrollViewer>
</Window>


能否请任何一个让我知道这种情况的解决方案?

谢谢
Sowndaiyan


Can you please any one let me know the solution for this scenario?

Thanks,
Sowndaiyan

推荐答案

从stackpanel和cancontentscroll中删除高度(或将其设置为false,因为内容不会像我想象的那样滚动),并从scrollviewer中删除宽度:

remove setting the height from the stackpanel and the cancontentscroll (or set it to false, since the content shall not scroll as I assume) and the width from the scrollviewer:

    <ScrollViewer  Name="ScrollViewer1"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalContentAlignment="Left" VerticalAlignment="Top" >
        <StackPanel Name="maindynamicStkPnl"  HorizontalAlignment="Left" IsEnabled="False"  ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
            <TextBox Height="1200" Text="Sowndaiyan"/>
            <!--<TextBox Height="1200" Text="Sowndaiyan"/>-->
        </StackPanel>
    </ScrollViewer>

此致

 托尔斯滕


这篇关于ScrollViewer不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆