【问题标题】:WPF Scrollviewer not scrolling... No thumb, only responds to mousewheelWPF Scrollviewer 不滚动...没有拇指,只响应鼠标滚轮
【发布时间】:2011-07-19 16:15:54
【问题描述】:

我有一个 WPF .Net 4 应用程序,其中包含一个按钮,单击该按钮会打开一个新窗口:

CreationWindow creationWindow = new CreationWindow();
creationWindow.Owner = this;
CreationWindow.Show();

窗口显示正常,但它包含的列表框(例如 100 个图像作为内容的列表框项)在滚动条上没有拇指。

这里是这个“CreationWindow”的内容示例

<Window
    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:Converters="clr-namespace:Krocr.Client.Converters"                  
    x:Class="Krocr.Client.ComparisonMode"
    Title="ComparisonMode" Height="450" Width="700">
  <Grid>
     <ListBox ItemsSource="{Binding Images}"/>
  </Grid>
</Window>

滚动条可见,但我无法与之交互。鼠标滚轮会滚动列表。

但是..

如果我在主窗口中添加一个滚动查看器,并向其中添加一些项目。随后的滚动查看器(在新窗口中)然后正常工作......

我根本没有为列表框或滚动查看器更改任何样式...非常困惑!

非常感谢您的帮助,因为这让我发疯了。

编辑:添加了问题的屏幕截图(由于我是新手,所以还不能发布图片......)

http://i.stack.imgur.com/XdYSs.png

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:

    这是因为默认情况下 Grid 不限制其子控件的大小,因此 ListBox 没有意识到它需要滚动。

    最快的解决方案是用 DockPanel 替换 Grid,这将约束其子控件,但如果您以后要添加更多子控件,则可能需要重新考虑!

    【讨论】:

    • 刚刚尝试过...不幸的是没有工作:(我不认为这是我的 xaml 的问题...更多某种渲染错误
    【解决方案2】:

    我想通了……

    这是我的 mainwindow.xaml 中的一个疯狂的可视化树,它破坏了其他所有内容的呈现...这是问题:

    <Grid Background="#00E5E5E5" Margin="0,75,0,0" Grid.Row="1">
            <Viewbox x:Name="docViewBox" Margin="0">
                <Grid  Margin="5" x:Name="holdingGrid">
                    <Canvas x:Name="AggLayer" Margin="0" />
    
                    <Canvas x:Name="rectCanvas"  MouseLeftButtonDown="StartDrag" MouseLeftButtonUp="EndDrag" Background="Transparent"/>
                    <ListBox x:Name="overlayCanvas" Background="#00FFFFFF"  IsHitTestVisible="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas Width="{Binding ActualWidth, ElementName=rectCanvas}" Height="{Binding ActualHeight, ElementName=rectCanvas}"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
    
                </Grid>
            </Viewbox>
            <Canvas x:Name="DialogLayer" Margin="0" />
        </Grid>
    

    有了评论,它工作正常......另外,xaml 完全破坏了混合,导致随机的疯狂行为......

    我觉得是时候优化了...感谢您的意见 :)

    编辑:事实上,我需要做的就是移除 Viewbox 并且一切正常......非常奇怪 编辑 2:罪魁祸首是带有画布项目面板的列表框,尤其是

    <Canvas Width="{Binding ActualWidth, ElementName=rectCanvas}" Height="{Binding ActualHeight, ElementName=rectCanvas}"/>
    

    绑定这些宽度和高度值会导致视图框进入无限缩放循环,这会破坏其他东西。傻了……

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2012-12-07
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      相关资源
      最近更新 更多