[英]WPF Scrollviewer not scrolling… No thumb, only responds to mousewheel
我有一个 WPF.Net 4 应用程序,其中包含一个按钮,单击该按钮会打开一个新的 windows:
CreationWindow creationWindow = new CreationWindow();
creationWindow.Owner = this;
CreationWindow.Show();
window 显示正常,但它包含的列表框(例如 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>
滚动条可见,但我无法与之交互。 鼠标滚轮确实滚动列表。
然而..
如果我在我的主 window 中添加一个滚动查看器,并向其中添加一些项目。 随后的滚动查看器(在新窗口中)然后正常工作......
我根本没有为列表框或滚动查看器更改任何 styles ......非常困惑!
帮助将不胜感激,因为它让我发疯。
编辑:添加了问题的屏幕截图(由于我是新手,所以还不能发布图片......)
这是因为默认情况下 Grid 不限制其子控件的大小,因此 ListBox 没有意识到它需要滚动。
最快的解决方案是用 DockPanel 替换 Grid,这将约束其子控件,但如果您以后要添加更多子控件,则可能需要重新考虑!
我想到了...
这是我的主窗口中的一棵疯狂的视觉树。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 项目面板的列表框,尤其是这个
<Canvas Width="{Binding ActualWidth, ElementName=rectCanvas}" Height="{Binding ActualHeight, ElementName=rectCanvas}"/>
绑定这些宽度和高度值会导致视图框进入无限缩放循环,这会破坏其他东西。 傻我...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.