【发布时间】:2012-05-05 14:54:09
【问题描述】:
Adam Nathan 撰写的“WPF 4 Unleashed”的第 10 章包含这个控制 ListBox 滚动行为的 XAML 示例:
<Window x:Class="NathanControllingScrollingBehavior.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="False"
ScrollViewer.IsDeferredScrollingEnabled="True">
...
</ListBox>
</Window>
本书中没有等效的 C# 示例。我做了一些研究,发现了一些迂回的方法来做到这一点。请参阅this SO question 了解两种对我有用的方法。然而,这些方法似乎有点骇人听闻。在 XAML 中调整这些属性非常简单,但在 C# 中却很麻烦。
这仅仅是 WPF 的一个区域,它只能用于 XAML 而不是 C#?谁能解释 XAML/C# 之间这些属性的易用性差异?这只是 WPF 团队的疏忽吗?
【问题讨论】:
标签: c# wpf xaml listbox scrollviewer