Tôi có một ListBox
hiển thị danh sách các điều khiển WPF. Vấn đề của tôi là thanh cuộn dọc hiển thị nhưng bị tắt ngay cả khi có đủ các mục mà ListBox
có thể cuộn được. Một thực tế khác có thể có liên quan là điều này được chứa trong một Integration.ElementHost
.Thanh cuộn trong Hộp danh sách không hoạt động
WPF noobie, Jim
Đây là XAML cho ListBox
:
// for brevity I removed the Margin and Tooltip attributes
<Grid x:Class="Xyzzy.NoteListDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Name="stackPanel" Orientation="Vertical"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<StackPanel Orientation="Horizontal">
<CheckBox Name="AllRecent" IsChecked="False" >View All Recent</CheckBox>
<CheckBox Name="AscendingOrder" IsChecked="False">Descending Order</CheckBox>
<Button Name="btnTextCopy" Click="btnCopyText_Click">Copy All</Button>
</StackPanel>
<ListBox Name="NoteList"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
</ListBox>
</StackPanel>
</Grid>
Và XAML cho điều khiển hiển thị trong mỗi ListBox
mục:
<UserControl x:Class="Xyzzy.NoteDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Name="Heading" FontSize="10">Note Heading</TextBlock>
<Button Name="btnCopyText" Height="20" FontSize="12"
Click="btnCopyText_Click">Copy
</Button>
</StackPanel>
<TextBlock Name="Body" FontSize="14">Note Body</TextBlock>
</StackPanel>
</Grid>
</UserControl>
Khi tôi đặt Listbox vào Grid thay vì StackPanel, vấn đề sẽ biến mất. Tôi đây là lỗi mã WPF, lỗi thiết kế WPF hoặc hành vi WPF có chủ ý? –
Tôi nghĩ đó chỉ là cách mà StackPanel hoạt động. Trong trường hợp của bạn, StackPanel cao bằng ListBox cần thiết mà không cần cuộn, thì StackPanel bị "cắt" ở phía dưới. –
Có, vấn đề là với StackPanel và sự cố được Grid giải quyết. Thanks @JohnMyczek –