1

我正在尝试创建一个扩展器,其中标题保持固定,内容显示在标题上方,覆盖上面的任何其他控件。将 Expander设置ExpandDirection="Up"并放置在 Canvas 中实现了一半 - 内容相对于标题向上扩展并覆盖其他控件(尽管在下方),但标题向下移动。

有没有办法做到这一点,但将标题保持在固定位置,以便内容最终覆盖上面的控件?

这是我到目前为止所生产的:

<Window x:Class="Sandbox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="900" Width="1100">
  <StackPanel>

    <StackPanel Margin="20,0,0,0">
      <RadioButton Content="Choice One"/>
      <RadioButton Content="Choice Two"/>
      <RadioButton Content="Choice Three"/>
      <RadioButton Content="Choice Four"/>
      <RadioButton Content="Choice Five"/>
      <RadioButton Content="Choice Six"/>
    </StackPanel>

    <Canvas MinHeight="25" Panel.ZIndex="99">
      <Expander Header="This must stay fixed" ExpandDirection="Up" Width="175">
        <Grid Background="Cornsilk">
          <Grid.BitmapEffect>
            <DropShadowBitmapEffect />
          </Grid.BitmapEffect>

          <TextBlock TextWrapping="Wrap" Margin="5">
            This must expand upwards, not downwards.
            The header must remain exactly where it is.
            This TextBlock must appear above the header
            and overlay the top radio buttons instead.
          </TextBlock>
        </Grid>
      </Expander>
    </Canvas>

    <StackPanel Margin="20,0,0,0">
      <RadioButton Content="Choice One"/>
      <RadioButton Content="Choice Two"/>
      <RadioButton Content="Choice Three"/>
      <RadioButton Content="Choice Four"/>
      <RadioButton Content="Choice Five"/>
      <RadioButton Content="Choice Six"/>
    </StackPanel>

  </StackPanel>
</Window>
4

2 回答 2

4

您可以使用 ToggleButton 和 Popup 而不是 Expander:

<Canvas MinHeight="25" Panel.ZIndex="99">
  <ToggleButton x:Name="toggle" Content="This must stay fixed" Width="175" />
  <Popup Placement="Top" PlacementTarget="{Binding ElementName=toggle}"
         IsOpen="{Binding ElementName=toggle, Path=IsChecked}">
      <Grid Background="Cornsilk" Width="175">
          <Grid.BitmapEffect>
              <DropShadowBitmapEffect />
          </Grid.BitmapEffect>

          <TextBlock TextWrapping="Wrap" Margin="5">
            This must expand upwards, not downwards.
            The header must remain exactly where it is.
            This TextBlock must appear above the header
            and overlay the top radio buttons instead.
          </TextBlock>
      </Grid>  
  </Popup>
</Canvas>
于 2010-12-09T12:11:22.303 回答
0

另一种方法是使用 CheckBox 控件而不是 ToggleButton。使用例如具有负边距值的 StackPanel 很容易隐藏框。此外,您不需要关心边界等。在某些情况下会容易得多。

于 2011-05-26T12:20:49.097 回答