扩展在一行中的不同列中。展开到完整行

时间:2011-10-24 12:05:21

标签: wpf xaml

我在一个网格行中有两个扩展器,但是在不同的列中。如何将每个扩展到整行,而不是仅扩展到列。

<Grid x:Name="mainGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="90"/>
        <ColumnDefinition Width="90"/>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition MinHeight="40" />
        <RowDefinition MinHeight="40" />
    </Grid.RowDefinitions>
    <Controls:Expander Grid.Row="0" Grid.Column="0" x:Name="expander2" Header="Header1" 
                           MinHeight="33" Padding="3">
        <TextBlock Text="SomeText1" />
    </Controls:Expander>

    <Controls:Expander Grid.Row="0" Grid.Column="1" x:Name="expander1" Header="Header2" 
                           MinHeight="33" Padding="3">
        <TextBlock Text="SomeText2" />
    </Controls:Expander>
</Grid>

expandder1和expandder2应该扩展到整行0。

1 个答案:

答案 0 :(得分:0)

介绍扩展程序的触发器,检查其IsExpanded属性并将其Grid.RowSpan设置为2。

    <Style TargetType="{x:Type Expander}">
       <Style.Triggers>
          <Trigger Property="IsExpanded" Value="True">
               <Setter Property="Grid.RowSpan" Value="2" />
          </Trigger>
       </Style.Triggers>
    </Style>

适用于silverlight

  <Style TargetType="{x:Type Expander}">
     <Setter Property="Grid.RowSpan"
             Value="{Binding IsExpanded,
                             RelativeSource={RelativeSource
                               Self},
                             Converter={StaticResource
                                local:ExpansionToRowSpanConverter}}"
   </Style>

代码背后......(这只是为了说明)

      ExpansionToRowSpanConverter.Convert(....)
      {
          return (bool)value ? 2 : 1;
      } 

这对你有用吗?