【问题标题】:WPF problem: Need to draw a control on top of anotherWPF问题:需要在另一个之上绘制一个控件
【发布时间】:2009-03-24 13:34:01
【问题描述】:

我有一个由页眉、主要内容和页脚构成的 shell 窗口。 主要内容是一个选项卡控件。 根据设计,其中一个选项卡项内容(用户控件)需要在页脚上方稍微扩展一点。 起初我考虑使用负边距来实现这一点,但无论我做什么,页脚总是被绘制在我的内容之上。

例如考虑以下 xaml:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="33*"/>
    <RowDefinition Height="33*"/>
    <RowDefinition Height="33*"/>
  </Grid.RowDefinitions>
  <StackPanel Background="Blue" Grid.Row="0"/> <!-- Header -->
  <StackPanel Background="Red" Grid.Row="2"/>  <!-- Footer -->
  <TabControl Grid.Row="1"  > <!-- Content -->
    <TabItem>
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="33*"/>
          <ColumnDefinition Width="33*"/>
          <ColumnDefinition Width="33*"/>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="1" Background="Yellow" >
          <Button Width="100" Height="50" Content="Text"  />
        </StackPanel>
      </Grid>
  </TabItem>
</TabControl>

我想要实现的是让黄色 StackPanel 以某种方式到达屏幕底部,重叠在红色页脚的顶部。

希望可以理解。 谢谢 爱丽儿

【问题讨论】:

    标签: c# wpf xaml layout


    【解决方案1】:

    试试这个代码示例:

    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="33*"/>
        <RowDefinition Height="33*"/>
        <RowDefinition Height="33*"/>
      </Grid.RowDefinitions>
       <Grid.ColumnDefinitions>
         <ColumnDefinition Width="33*"/>
         <ColumnDefinition Width="33*"/>
         <ColumnDefinition Width="33*"/>
       </Grid.ColumnDefinitions>      
      <StackPanel Grid.ColumnSpan="3" Background="Blue" Grid.Row="0"/> <!-- Header -->
      <StackPanel Grid.ColumnSpan="3" Background="Red" Grid.Row="2"/>  <!-- Footer -->
      <TabControl Grid.ColumnSpan="3" Grid.Row="1"> <!-- Content -->
        <TabItem>
          <Grid>
              <Button Width="100" Grid.Column="1" Height="50" Content="Text"  />          
          </Grid>
        </TabItem>
      </TabControl>
        <StackPanel Grid.Column="1" Grid.Row="3" Background="Yellow" />
    </Grid>
    

    【讨论】:

    • 谢谢老兄,但你误会了。屏幕底部,而不是选项卡控件的底部。黄色的堆栈面板需要重叠在红色的顶部。
    • 啊,我的错……稍微改变了我的答案:)
    • 没有。如果将 Grid.Row 更改为 2,您将完全丢失页脚我希望只有黄色 StackPanel 位于红色之上,而不是整个选项卡控件。
    • 太好了,现在您不仅覆盖了页脚,还覆盖了页眉! :)
    • :) 不完全。 TabControl 失去了他在屏幕中间的位置...
    【解决方案2】:

    问题是您希望堆栈面板包含在选项卡控件中,但您希望它超出选项卡控件的底部。选项卡控件不支持此功能。

    【讨论】:

    • 解决方法是为此创建一个自定义控件。或者,重新考虑您的设计。我不确定你为什么要这样做,或者认为它值得付出努力。
    【解决方案3】:

    毫无疑问 TabControl 是问题所在。也许尝试编写自己的 TabControl。

    干杯。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      相关资源
      最近更新 更多