2011-12-05 66 views
0

我有一个网格中有几个文本框。我想保持这个网格固定在我的主窗口的底部。所以,如果用户向下滚动网格,基本上应该留在它的位置。保持在可见区域的控件

我认为这样做的一种方式是从ScrollViewer获得某种价值,并将其添加到网格Canvas.TopProperty中。但是我不确定当用户向上或向下滚动时哪个值发生了变化。

回答

3

然后不要在主窗口上的滚动。仅将ScrollViewer放在要滚动的内容(行)上。小心不要使用自动滚动查看器的行高度或容器将增长到支持所有的内容和滚动不起作用。

0

方式一:

<Window x:Class="Sample.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"> 
<Grid> 
    <ListBox> 
     <!--Hardcoded listbox items just to force the scrollbar for demonstration purposes --> 
     <ListBoxItem>Item1</ListBoxItem> 
     <ListBoxItem>Item2</ListBoxItem> 
     <ListBoxItem>Item3</ListBoxItem> 
     <ListBoxItem>Item4</ListBoxItem> 
     <ListBoxItem>Item5</ListBoxItem> 
     <ListBoxItem>Item6</ListBoxItem> 
     <ListBoxItem>Item7</ListBoxItem> 
     <ListBoxItem>Item8</ListBoxItem> 
     <ListBoxItem>Item9</ListBoxItem> 
     <ListBoxItem>Item10</ListBoxItem> 
     <ListBoxItem>Item11</ListBoxItem> 
     <ListBoxItem>Item12</ListBoxItem> 
     <ListBoxItem>Item14</ListBoxItem> 
     <ListBoxItem>Item15</ListBoxItem> 
     <ListBoxItem>Item16</ListBoxItem> 
     <ListBoxItem>Item17</ListBoxItem> 
     <ListBoxItem>Item18</ListBoxItem> 
     <ListBoxItem>Item19</ListBoxItem> 
     <ListBoxItem>Item20</ListBoxItem> 
     <ListBoxItem>Item21</ListBoxItem> 
     <ListBoxItem>Item22</ListBoxItem> 
    </ListBox> 
    <Grid Panel.ZIndex="5" VerticalAlignment="Bottom" Background="DarkGray"> 
     <StackPanel> 
      <TextBox HorizontalAlignment="Left" VerticalAlignment="Center">Text box 1</TextBox> 
      <TextBox HorizontalAlignment="Left" VerticalAlignment="Center">Text box 2</TextBox> 
      <TextBox HorizontalAlignment="Left" VerticalAlignment="Center">Text box 3</TextBox> 
     </StackPanel> 
    </Grid> 
</Grid> 

相关问题