简体   繁体   English

扩展器标头的旋转文本宽度不正确

[英]Expander header has incorrect width with rotated text

I have an (right-direction) expander which should hide the header when expanded, and display some text rotated to be vertical down the right hand side when it is collapsed. 我有一个(右向)扩展器,它应该在展开时隐藏标题,并在折叠时显示一些旋转到右下方垂直的文本。 I have managed to achieve this using the following code: 我已设法使用以下代码实现此目的:

<Expander Grid.Column="1" ExpandDirection="Left" 
      IsExpanded="True" Name="rightHandExpander"
      MaxWidth="{Binding RelativeSource={RelativeSource PreviousData}}">
    <Expander.Header>
        <TextBlock Text="Header text" RenderTransformOrigin="0,0"
            Visibility="{Binding IsExpanded, RelativeSource={RelativeSource 
                         AncestorType={x:Type Expander}, Mode=FindAncestor}, 
                         Converter={StaticResource boolToVisibilityConverter}}">
            <TextBlock.LayoutTransform>
                <TransformGroup>
                    <RotateTransform CenterX="25" CenterY="25" Angle="90" />
                </TransformGroup>
            </TextBlock.LayoutTransform>
        </TextBlock>
    </Expander.Header>
    <!-- controls here -->
</Expander>

However when the expander is collapsed, the header takes up far too much space- the text is rotated, but the header's width appears to remain as if it has not. 但是,当展开器折叠时,标头会占用太多空间 - 文本会旋转,但标题的宽度似乎仍然保持不变。

Using VisualTreeHelper in the code-behind I discovered that the expander's header, border and dockpanel were too large, but the inner toggle button was the correct size. 在代码隐藏中使用VisualTreeHelper我发现扩展器的标题,边框和dockpanel太大,但内部切换按钮的大小正确。 I tried setting the header, border and dockpanel's width to the correct size but they did not change. 我尝试将标题,边框和dockpanel的宽度设置为正确的大小,但它们没有更改。

Can anyone help? 有人可以帮忙吗?

Edit: The expander is contained in a grid with two columns with a grid splitter and another expander in the first column. 编辑:扩展器包含在一个网格中,其中两列带有网格分割器,第一列中有另一个扩展器。 The other expander does the same thing but collapsing to the left hand side- this expander seems to work correctly, however. 另一个扩展器做同样的事情但是向左侧折叠 - 然而这个扩展器似乎正常工作。

I believe setting 'HorizontalAlignment' to 'Right' may fix the behaviour you are getting, as the default behaviour of most controls in a grid will be to fill all available space in their cell. 我认为将“Horizo​​ntalAlignment”设置为“Right”可能会修复您获得的行为,因为网格中大多数控件的默认行为是填充其单元格中的所有可用空间。 It is kind of strange your left one works though, unless it is not directly in a grid, or has HorizontalAlignment set to Left? 你的左边工作有点奇怪,除非它不直接在网格中,或者Horizo​​ntalAlignment设置为Left?

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

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