获取或设置一个值,该值指示是否允许滚动支持 IScrollInfo 接口的元素。Gets or sets a value that indicates whether elements that support the IScrollInfo interface are allowed to scroll.
public:
property bool CanContentScroll { bool get(); void set(bool value); };
public bool CanContentScroll { get; set; }
member this.CanContentScroll : bool with get, set
Public Property CanContentScroll As Boolean
属性值
true(如果 ScrollViewer 按逻辑单位滚动);false(如果 ScrollViewer 按物理单位滚动),true if the ScrollViewer scrolls in terms of logical units; false if the ScrollViewer scrolls in terms of physical units. 默认值为 false。The default is false.
示例
下面的示例演示如何 CanContentScroll 使用代码设置属性。The following example demonstrates how to set the CanContentScroll property by using code.
private void scrollTrue(object sender, RoutedEventArgs e)
{
svrContent.CanContentScroll = true;
svrContent.Height = 600;
myStackPanel.Visibility = Visibility.Visible;
btnEnableContentScrolling.Visibility = Visibility.Collapsed;
}Private Sub scrollTrue(ByVal sender As Object, ByVal args As RoutedEventArgs)
sv1.CanContentScroll = True
sv1.Height = 600
myStackPanel.Visibility = Visibility.Visible
btn1.Visibility = Visibility.Collapsed
End Sub
注解
中的内容 ScrollViewer 可以根据物理单元或逻辑单元进行滚动。Content in a ScrollViewer can be scrolled in terms of physical units or logical units. 物理单元是与设备无关的像素。Physical units are device independent pixels. 逻辑单元用于在中滚动项 ItemsControl 。Logical units are used for scrolling items within an ItemsControl. 的默认行为 ScrollViewer 是使用物理单元滚动其内容。The default behavior of the ScrollViewer is to use physical units to scroll its content. 但是,在设置为的情况下 CanContentScroll true ,内容可以使用逻辑单元进行滚动。However, in cases where the CanContentScroll is set to true, the content could use logical units to scroll. For example, ListBox, ListView, and other controls that inherit from ItemsControl use logical units to scroll. If CanContentScroll is true, the values of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items, instead of physical units.
如果需要物理滚动而不是逻辑滚动,请 Panel 在中包装主机元素, ScrollViewer 并将其 CanContentScroll 属性设置为 false 。If you require physical scrolling instead of logical scrolling, wrap the host Panel element in a ScrollViewer and set its CanContentScroll property to false. 物理滚动是大多数元素的默认滚动行为 Panel 。Physical scrolling is the default scroll behavior for most Panel elements.
依赖项属性信息Dependency Property Information
元数据属性设置为 trueMetadata properties set to true
无None
适用于