默认情况下,扩展器有一个左对齐的切换按钮,但在我的WPF应用程序中,我希望在没有Expression Blend帮助的情况下切换标题右侧的按钮。只是简单的XAML和/或C#。我的扩展器包含一个垂直方向的stackpanel,它有标签作为它的子项。
我去了它的部分但是here它说“Expander控件没有任何命名的部分”。
我找到了一个例子here。但它会覆盖默认的扩展器样式。
我认为附图应该表达我想要的东西。怎么做。任何链接都会有所帮助。
答案 0 :(得分:15)
有一个技巧可以帮助
<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>
答案 1 :(得分:9)
使用此:
<Expander Header="Expander1" FlowDirection="RightToLeft">
<TextBlock FlowDirection="LeftToRight">
</TextBlock>
</Expander>
如果您不希望整个内容从右到左,请在TextBlock
中添加您的内容。