Ich habe eine ListBox
, die eine Liste von WPF-Steuerelemente angezeigt. Mein Problem ist, dass der vertikale Bildlauf Show ist aber deaktiviert, auch wenn es genügend Elemente, die die ListBox
scrollbaren sein sollten. Eine andere möglicherweise relevante Tatsache ist, dass dies in einem Integration.ElementHost
enthalten ist.Scrollbar in Listbox arbeiten nicht
WPF noobie, Jim
ist die XAML für die 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>
Und das XAML für die in jedem ListBox
Element angezeigt Kontrolle:
<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>
Wenn ich Listbox in Grid statt StackPanel einsetzte, verschwand das Problem. Ich dies ein WPF-Code-Bug, WPF-Design-Bug oder absichtliche WPF-Verhalten ?? –
Ich denke, es ist nur die Art, wie das StackPanel funktioniert. In Ihrem Fall war das StackPanel so groß wie die ListBox ohne Scrollen, dann wurde das StackPanel unten abgeschnitten. –
Ja, das Problem ist mit StackPanel und das Problem wird von Grid gelöst. Danke @JohnMyczek –