Как заставить WPF Expander расширяться вверх при сохранении фиксированного заголовка - PullRequest
1 голос
/ 09 декабря 2010

Я пытаюсь создать Expander, в котором заголовок остается неизменным, а содержимое отображается над заголовком, перекрывая любые другие элементы управления выше. Установка ExpandDirection="Up" и размещение Expander внутри 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>

Ответы [ 2 ]

3 голосов
/ 09 декабря 2010

Вы можете использовать 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>
0 голосов
/ 26 мая 2011

Другой способ - использовать элемент управления CheckBox вместо ToggleButton. Коробку легко спрятать, например, с помощью StackPanel с отрицательным значением маржи. Также вам не нужно заботиться о границах и т. Д. В некоторых случаях это намного проще.

...