如何将Expander ToggleButton放在右边

Nik*_*wal 8 c# wpf expander

默认情况下,扩展器有一个左对齐的切换按钮,但在我的WPF应用程序中,我希望在没有Expression Blend帮助的情况下切换标题右侧的按钮.只是简单的XAML和/或C#.我的扩展器包含一个垂直方向的stackpanel,它有标签作为它的子.

我去了它的部分,但在这里它说"Expander控件没有任何命名的部分".

我在这里找到了一个例子.但它会覆盖默认的Expander Style.

我认为附加的图像应该表达我想要的东西.怎么做.任何链接都会有所帮助.

在此输入图像描述

Nit*_*esh 16

有一个技巧可以帮助

<Expander Header="My Expander" 
          FlowDirection="RightToLeft">
    <Expander.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}"
                       Width="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=ActualWidth}" 
                       Margin="-30,0,0,0"
                       FlowDirection="LeftToRight">
            </TextBlock>
        </DataTemplate>
    </Expander.HeaderTemplate>
</Expander>
Run Code Online (Sandbox Code Playgroud)


Moh*_*han 9

用这个:

<Expander Header="Expander1" FlowDirection="RightToLeft">
    <TextBlock FlowDirection="LeftToRight">
    </TextBlock>
</Expander>
Run Code Online (Sandbox Code Playgroud)

TextBlock如果您不希望整个内容从右到左,请添加您的内容.

  • 这会将标题对齐到窗口的右侧。 (2认同)