2011-10-24 55 views
1

我在一個網格行中有兩個擴展器,但在不同的列中。我怎樣才能將它擴展到整行,而不是隻在列上。一行中不同列的擴展。擴展到整行

<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> 

expander1和expander2應擴大到整個行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; 
     } 

這是否對你的工作?

+0

非常感謝,它工作正常。你可以給任何建議解決這個問題在Silverlight中不支持觸發器? – scor4er

+0

請參閱我上面編輯的答案。 –