首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ScrollViewer未滚动

ScrollViewer未滚动
EN

Stack Overflow用户
提问于 2009-08-16 15:49:44
回答 2查看 9.1K关注 0票数 3

下面的滚动查看器不起作用。我尝试了在这个网站和其他网站上能找到的所有东西:在网格中嵌入scrollviewer,在网格中嵌入scrollviewer的子项,在固定高度的StackPanel中嵌入Scrollviewer,设置/绑定scrollviewer的高度,所有这些都没有用……是谁指引我恢复理智的??

请注意,下面的XAML只是为了展示窗口的结构。我删除了所有的数据。

代码语言:javascript
复制
<Window>
    <Window.Resources>
        <DataTemplate x:Key="ColoringLabels">
        </DataTemplate>
    </Window.Resources>
    <DockPanel>
        <StatusBar DockPanel.Dock="Top">
            <StatusBarItem>
            </StatusBarItem>
        </StatusBar>
        <StackPanel Orientation="Vertical">
            <TextBox/>
            <Button>Hello World!</Button>
            <ScrollViewer>
                <StackPanel Orientation="Vertical">
                    <Label>Hola Mundo!</Label>
                    <ListBox ItemsSource="{Binding}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <ListBox ItemsSource="{StaticResource ColoringLabels}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/>
                </StackPanel>
            </ScrollViewer>
            <TextBlock/>
        </StackPanel>
    </DockPanel>
</Window>

编辑:

我通过将XAML更改为:

代码语言:javascript
复制
<Window>
   <Window.Resources>
       <DataTemplate x:Key="ColoringLabels">
       </DataTemplate>
   </Window.Resources>
   <DockPanel>
       <StatusBar DockPanel.Dock="Top">
           <StatusBarItem>
           </StatusBarItem>
       </StatusBar>
       <ScrollViewer>
            <StackPanel Orientation="Vertical">
                <TextBox />
                <Button>Hello World!</Button>
                    <StackPanel Orientation="Vertical">
                        <Label>Hola Mundo!</Label>
                        <ListBox ItemsSource="{Binding}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <ListBox ItemsSource="{StaticResource ColoringLabels}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        <ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/>
                    </StackPanel>
                <TextBlock/>
            </StackPanel>
        </ScrollViewer>
    </DockPanel>
</Window>

为什么它现在能工作?也许是因为ScrollViewer现在填补了DockPanel的LastChild位置?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-08-16 16:41:28

尝尝这个

代码语言:javascript
复制
<Window x:Class="WpfApplication7.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="308" Width="527">
    <Window.Resources>
        <DataTemplate x:Key="ColoringLabels">
        </DataTemplate>
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch">
            <StatusBar>
                <StatusBarItem>
                </StatusBarItem>
            </StatusBar>
            <TextBox/>
            <Button>Hello World!</Button>
        </StackPanel>
        <ScrollViewer>
            <StackPanel Orientation="Vertical" >
                <Label>Hola Mundo!</Label>
                <ListBox ItemsSource="{Binding}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <ListBox />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <ListBox />
            </StackPanel>
        </ScrollViewer>
        <TextBlock/>
    </DockPanel>

</Window>

编辑

你的新代码可以工作了,因为scrollviewer的大小现在是固定的(它填满了屏幕的空闲部分),当它的内容在增长时,它不会在窗口外增长……

票数 4
EN

Stack Overflow用户

发布于 2009-08-16 16:14:31

尝试在滚动查看器中为列表框或堆叠面板赋予高度,当内容大于您的案例中的大小时,滚动查看器会滚动。当您向列表框添加项目时,列表框的高度不会增长,而列表框正在滚动

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1284600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档