简体   繁体   English

如何将Expander ToggleButton放在右边

[英]How to put Expander ToggleButton on right

By default the expander has a left aligned toggle button but in my WPF app i want toggle button on the right side of the header without the help of Expression Blend. 默认情况下,扩展器有一个左对齐的切换按钮,但在我的WPF应用程序中,我希望在没有Expression Blend帮助的情况下切换标题右侧的按钮。 just plain XAML and/or C#. 只是简单的XAML和/或C#。 My expander contains a vertically oriented stackpanel which has labels as its child. 我的扩展器包含一个垂直方向的stackpanel,它有标签作为它的子。

I went for its part but here it says "The Expander control does not have any named parts". 我去了它的部分,但在这里它说“Expander控件没有任何命名的部分”。

I found an example here . 我在这里找到了一个例子。 But it overrides the default Expander Style. 但它会覆盖默认的Expander Style。

I think the attached image should convey what i want. 我认为附加的图像应该表达我想要的东西。 How to do. 怎么做。 Any link would be helpful. 任何链接都会有所帮助。

在此输入图像描述

There is a trick that can help 有一个技巧可以帮助

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

Use this: 用这个:

<Expander Header="Expander1" FlowDirection="RightToLeft">
    <TextBlock FlowDirection="LeftToRight">
    </TextBlock>
</Expander>

Add your content in the TextBlock , if you don't want to the whole content to be right to left. 如果您不希望整个内容从右到左,请在TextBlock添加内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM