我一直在努力在我的wpf应用程序中使网格可滚动而滚动查看器不工作所以我需要类似于溢出的东西:在CSS中滚动所以如果有人可以帮助我会非常感激
<Grid Margin="12,49,0,54" Name="state_settings" Width="430" Visibility="Hidden" MaxHeight="200" Height="200" HorizontalAlignment="Left" VerticalAlignment="Top">
<ScrollViewer VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<Grid Height="69" HorizontalAlignment="Left" Margin="13,10,0,0" Name="state_comp" VerticalAlignment="Top" Width="406">
<Label Content="Gesture" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" Width="103" FontWeight="Bold" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="6,31,0,0" Name="comboBox1" VerticalAlignment="Top" Width="103" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="167,31,0,0" Name="textBox1" VerticalAlignment="Top" Width="27" />
<Label Content="Min Duration" Height="28" HorizontalAlignment="Left" Margin="135,6,0,0" Name="label2" VerticalAlignment="Top" Width="89" FontWeight="Bold" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="258,31,0,0" Name="textBox2" VerticalAlignment="Top" Width="27" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="346,31,0,0" Name="textBox3" VerticalAlignment="Top" Width="36" />
<Label Content="Max Duration" Height="28" HorizontalAlignment="Left" Margin="230,6,0,0" Name="label3" VerticalAlignment="Top" Width="89" FontWeight="Bold" />
<Label Content="Transition" Height="28" HorizontalAlignment="Left" Margin="327,6,0,0" Name="label4" VerticalAlignment="Top" Width="71" FontWeight="Bold" />
</Grid>
</ScrollViewer>
</Grid>
答案 0 :(得分:1)
我必须更改一些内容,以便更轻松地使用您的代码...例如,我必须删除Visibility="Hidden"
,这对您来说是非常荒谬的。我还添加了Background
颜色,以便我可以看到Grid
的边界。我将ScrollViewer
移动为最外层元素并删除了不必要的CanContentScroll
属性和一些Height
设置,但除此之外,您几乎已经拥有它。试试这个:
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid Name="state_settings" Width="430" MaxHeight="200" Background="LightBlue" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Height="69" HorizontalAlignment="Left" Margin="13,10,0,0" Name="state_comp" VerticalAlignment="Top" Width="406">
<Label Content="Gesture" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" Width="103" FontWeight="Bold" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="6,31,0,0" Name="comboBox1" VerticalAlignment="Top" Width="103" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="167,31,0,0" Name="textBox1" VerticalAlignment="Top" Width="27" />
<Label Content="Min Duration" Height="28" HorizontalAlignment="Left" Margin="135,6,0,0" Name="label2" VerticalAlignment="Top" Width="89" FontWeight="Bold" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="258,31,0,0" Name="textBox2" VerticalAlignment="Top" Width="27" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="346,31,0,0" Name="textBox3" VerticalAlignment="Top" Width="36" />
<Label Content="Max Duration" Height="28" HorizontalAlignment="Left" Margin="230,6,0,0" Name="label3" VerticalAlignment="Top" Width="89" FontWeight="Bold" />
<Label Content="Transition" Height="28" HorizontalAlignment="Left" Margin="327,6,0,0" Name="label4" VerticalAlignment="Top" Width="71" FontWeight="Bold" />
</Grid>
</Grid>
</ScrollViewer>
您可能需要减少Height
的{{1}},或添加更多项目才能真正看到垂直Window
,但如果您这样做,你现在应该看到它滚动。
您的用户界面 a ScrollBar
: