1
我有一個TabItem
裏面有很多元素,我想讓ListView
可以垂直滾動但是讓按鈕保持在頂部(不滾動)。我嘗試在ScrollViewer
中包裝ListView
,但它不會滾動。我可以將ScrollViewer
放在ItemsControl
之外,並更新RowDefinition Height="*"
以及包括按鈕在內的所有內容滾動,但這不是我所需要的。ListView不會滾動垂直
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Menu Grid.Row="0" KeyboardNavigation.TabNavigation="Cycle">
<MenuItem Header="File">
<MenuItem Header="Exit" />
</MenuItem>
<MenuItem Header="Options" />
<MenuItem Header="Help" />
</Menu>
<TextBlock Grid.Row="1" Text="Test" Height="23" Width="Auto" HorizontalAlignment="Left" TextWrapping="Wrap"/>
<TabControl Grid.Row="2" >
<TabItem Header="TabItem1">
<ItemsControl>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding Button1}" Width="150" Margin="5" Height="22" HorizontalAlignment="Left">Button1</Button>
<Button Command="{Binding Button2}" CommandParameter="{Binding ElementName=listView}" Width="150" Margin="5" Height="22" HorizontalAlignment="Left">Button2</Button>
</StackPanel>
<ScrollViewer>
<ListView Name="listView" Grid.Row="1" BorderThickness="0" ItemsSource="{Binding myItems}">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" Width="Auto" />
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="Auto" />
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</ItemsControl>
</TabItem>
... Other tabs
</TabControl>
</Grid>
完美。感謝您的解釋! – yellavon 2014-11-08 18:12:30
沒問題@yellavon。很高興幫助 – dkozl 2014-11-08 18:17:01