ControlTemplate

时间:2018-08-09 12:25:45

标签: wpf xaml templates togglebutton expander

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>

1 个答案:

答案 0 :(得分:0)

从评论中看,我认为您正在寻找一个扩展器,该扩展器的标题在左侧,而箭头按钮(切换)在右侧。

enter image description here

如果是这样,则可以使用链接到here的Material Design工具包扩展器。

您还可以探索更多的材料设计工具包here