如何将 Expander ToggleButton 放在右侧

发布于 2025-01-05 10:07:35 字数 516 浏览 5 评论 0原文

默认情况下,扩展器有一个左对齐的切换按钮,但在我的 WPF 应用程序中,我希望切换按钮位于标题的右侧,而不需要 Expression Blend 的帮助。只是简单的 XAML 和/或 C#。我的扩展器包含一个垂直方向的堆栈面板,其中标签作为其子项。

我去了它的部分,但这里它说“扩展器控件确实没有任何命名零件”。

我在此处找到了一个示例。但它会覆盖默认的扩展器样式。

我认为所附图片应该传达我想要的内容。怎么办。任何链接都会有帮助。

在此处输入图像描述

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. just plain XAML and/or C#. My expander contains a vertically oriented stackpanel which has labels as its child.

I went for its part but here it says "The Expander control does not have any named parts".

I found an example here. But it overrides the default Expander Style.

I think the attached image should convey what i want. How to do. Any link would be helpful.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

§普罗旺斯的薰衣草 2025-01-12 10:07:35

有一个技巧可以帮助你

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

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>
凌乱心跳 2025-01-12 10:07:35

使用此方法:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文