0
如果ScrollViewer
不是窗口中的唯一元素,我无法正常工作。我想滚动项目列表(列表设置为ItemsSource
),但也希望其他元素在我的窗口中可见。现在我不知道如何设置相对于其他元素的height
。这是一种有效的方法,还是我完全错了?什么是在Wpf中实现ScrollViewer的动态方式
<Window x:Class="FactorioWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FactorioWpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
Closing="Window_Closing">
<StackPanel>
<Menu>
<MenuItem Header="Items">
<MenuItem Header="Add" Click="ItemsAdd_Click" />
</MenuItem>
</Menu>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0">
<ItemsControl Name="ItemViewerItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</StackPanel>
我搜索了将近三个小时,但唯一的解决方案,我可以找到,分别设置滚动浏览器的顶级元素。
首先,您正在使用没有RowDefinition的网格。这是打算吗? 你尝试过StackPanel吗? RowDefinition? DockPanel中?列表显示? –