如何在wp7上的silverlight中始终将控件定位到屏幕上的固定位置?

时间:2012-01-05 08:36:04

标签: silverlight xaml windows-phone-7

无论客户端更改焦点的文本框如何,我如何始终将Silverlight控件放在同一位置的屏幕上?基本上我有一个我想要随时可见的标题横幅。当客户端将焦点更改为文本框时,我希望所有内容都滚动以将文本框置于中心视图(这是默认行为),但应始终显示在(0,0)屏幕坐标处的横幅除外。我到目前为止的布局是:

<Grid x:Name="LayoutRoot"
      Background="Transparent">

    <Grid.RowDefinitions>
        <RowDefinition Height="80" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <TextBlock Name="myBanner"
               VerticalAlignment="Top"
               HorizontalAlignment="Left"
               Height="80"
               Width="480" />

    <TextBox Grid.Row="2"
             Name="textBox1"
             Text="TextBox"
             VerticalAlignment="Top"
             HorizontalAlignment="Left"
             Height="72"
             Width="480"
             />                  <--- Even when client focuses on this I want myBanner to be visible at (0,0) screen coordinate
</Grid>

可以在手机上的短信应用中看到这方面的一个例子。无论客户端是否专注于文本消息编写文本框,顶部的标题“John Doe,Text”始终出现在同一位置。

再次感谢您的帮助。

1 个答案:

答案 0 :(得分:-1)

试试这个

  <Grid>
     <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />

        <RowDefinition />
     </Grid.RowDefinitions>
     <!-- Your banner goes here-->
     <TextBlock Text="some text" />
     <ScrollViewer Grid.Row="1">
         <!-- Your content goes here-->
     </ScrollViewer>

  </Grid>