C# ScrollView内部的StackPanel无法正确地进行物理滚动
考虑以下XAML(用户控件):C# ScrollView内部的StackPanel无法正确地进行物理滚动,c#,wpf,xaml,scrollview,stackpanel,C#,Wpf,Xaml,Scrollview,Stackpanel,考虑以下XAML(用户控件): scrollview和stackpanel的水平偏移仍然为零!此外,stackpanel的ScrollOwner为空。有什么想法吗?因为您没有指定ScrollViewer的宽度,所以它采用StackPanel的大小。因为ScrollViewer的内容不大于其大小,所以它不会滚动,并且水平偏移量始终为0。尝试将ScrollViewer的宽度设置为小于其内容的宽度,您应该可以使用水平滚动 此外,还可以删除禁用垂直滚动条的所有冗余,一次就足够了 <Grid x:N
scrollview和stackpanel的水平偏移仍然为零!此外,stackpanel的ScrollOwner为空。有什么想法吗?因为您没有指定ScrollViewer的宽度,所以它采用StackPanel的大小。因为ScrollViewer的内容不大于其大小,所以它不会滚动,并且水平偏移量始终为0。尝试将ScrollViewer的宽度设置为小于其内容的宽度,您应该可以使用水平滚动 此外,还可以删除禁用垂直滚动条的所有冗余,一次就足够了
<Grid x:Name="LayoutRoot">
<Grid HorizontalAlignment="Right" Width="335.312">
<ed:BlockArrow Fill="#FFF4F4F5" HorizontalAlignment="Left" Margin="0"
Orientation="Left" Stroke="Black" Width="15" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="LeftArrow_MouseEnter"
MouseLeave="LeftArrow_MouseLeave" MouseLeftButtonUp="LeftArrow_MouseLeftButtonUp"/>
<ed:BlockArrow Fill="#FFF4F4F5" Stroke="Black" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="RightArrow_MouseEnter"
MouseLeave="RightArrow_MouseLeave" HorizontalAlignment="Right" Width="15"
MouseLeftButtonUp="RightArrow_MouseLeftButtonUp"/>
<ScrollViewer x:Name="panelScrollViewer" Margin="15,0" CanContentScroll="False"
VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden"
Width="250">
<StackPanel x:Name="slidingStackPanel" Orientation="Horizontal" Height="125.882" Width="305.312"/>
</ScrollViewer>
</Grid>
由于您没有指定ScrollViewer的宽度,因此它采用StackPanel的大小。因为ScrollViewer的内容不大于其大小,所以它不会滚动,并且水平偏移量始终为0。尝试将ScrollViewer的宽度设置为小于其内容的宽度,您应该可以使用水平滚动 此外,还可以删除禁用垂直滚动条的所有冗余,一次就足够了
<Grid x:Name="LayoutRoot">
<Grid HorizontalAlignment="Right" Width="335.312">
<ed:BlockArrow Fill="#FFF4F4F5" HorizontalAlignment="Left" Margin="0"
Orientation="Left" Stroke="Black" Width="15" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="LeftArrow_MouseEnter"
MouseLeave="LeftArrow_MouseLeave" MouseLeftButtonUp="LeftArrow_MouseLeftButtonUp"/>
<ed:BlockArrow Fill="#FFF4F4F5" Stroke="Black" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="RightArrow_MouseEnter"
MouseLeave="RightArrow_MouseLeave" HorizontalAlignment="Right" Width="15"
MouseLeftButtonUp="RightArrow_MouseLeftButtonUp"/>
<ScrollViewer x:Name="panelScrollViewer" Margin="15,0" CanContentScroll="False"
VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden"
Width="250">
<StackPanel x:Name="slidingStackPanel" Orientation="Horizontal" Height="125.882" Width="305.312"/>
</ScrollViewer>
</Grid>
<Grid x:Name="LayoutRoot">
<Grid HorizontalAlignment="Right" Width="335.312">
<ed:BlockArrow Fill="#FFF4F4F5" HorizontalAlignment="Left" Margin="0"
Orientation="Left" Stroke="Black" Width="15" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="LeftArrow_MouseEnter"
MouseLeave="LeftArrow_MouseLeave" MouseLeftButtonUp="LeftArrow_MouseLeftButtonUp"/>
<ed:BlockArrow Fill="#FFF4F4F5" Stroke="Black" RenderTransformOrigin="5.6,-0.412"
Height="12" VerticalAlignment="Center" MouseEnter="RightArrow_MouseEnter"
MouseLeave="RightArrow_MouseLeave" HorizontalAlignment="Right" Width="15"
MouseLeftButtonUp="RightArrow_MouseLeftButtonUp"/>
<ScrollViewer x:Name="panelScrollViewer" Margin="15,0" CanContentScroll="False"
VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden"
Width="250">
<StackPanel x:Name="slidingStackPanel" Orientation="Horizontal" Height="125.882" Width="305.312"/>
</ScrollViewer>
</Grid>