Expander
应该是左侧的HeaderText
和右侧的ToggleButton
。
我尝试将ToggleButton
设置为默认样式,而不为其创建新的完全ControlTemplate
。
有人可以帮忙吗?
<ControlTemplate TargetType="Expander" x:Key="ExpanderControlx">
<Grid Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Name="ContentRow" Height="0"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<ToggleButton Grid.Column="1"
IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
OverridesDefaultStyle="True"
Template="{StaticResource {x:Type ToggleButton}}"
/>
<TextBlock Grid.Column="0" Eddie.TextFormat="Header1" Text="{TemplateBinding Header}" HorizontalAlignment="Left" />
</Grid>
</Border>
<Border Grid.Row="1" Name="ContentText" >
<StackPanel>
<ContentPresenter/>
</StackPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=ContentText, Path=Height}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="controls:ExpanderControl">
<Setter Property="Template" Value="{StaticResource ExpanderControlx}" />
</Style>