简体   繁体   English

在固定宽度的网格内重叠旋转的Textblock

[英]Overlapping rotated Textblock inside fixed width Grid

I have UserControl which represents a header. 我有代表标题的UserControl。 The header text can be pretty long, so rotating solves the problem. 标头文字可能会很长,因此旋转可以解决问题。 Each colum should be 60 DPI, but as soon the text uses up more than 60 the text is no longer visible. 每个列应为60 DPI,但是一旦文本用完超过60个,该文本将不再可见。 Is Grid the right class to use? Grid是适合使用的类吗?

To make the long story short, below is the sample of what I try to achieve (fist picture) and what I have (2nd one). 长话短说,下面是我尝试实现的目标(第一张图片)和我拥有的目标(第二个示例)的示例。

上图是成就,下图是我所拥有的 Below is the xaml of the 2nd picture: 以下是第二张图片的xaml:

<UserControl>
<Grid Height="Auto">
    <Grid.Resources>
        <Style x:Key="StyleGrid" TargetType="Grid">
            <Setter Property="VerticalAlignment" Value="Bottom" />
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="RenderTransformOrigin" Value="0,0.5" />
            <!--  <Setter Property="LayoutTransform">  -->
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <RotateTransform Angle="330" />
                </Setter.Value>
            </Setter>
        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="24" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="492" />
    </Grid.ColumnDefinitions>

    <!--  Header  -->
    <TextBlock Grid.Row="0"
               Grid.Column="0"
               Grid.ColumnSpan="2"
               FontSize="14"
               FontWeight="Bold"
               Text="Date 14.08.2014" />
    <TextBlock Grid.Row="1"
               Grid.Column="0"
               Margin="1,0,0,0"
               FontSize="18"
               Text="This is the Title" />

    <Grid Grid.Row="0"
          Grid.RowSpan="2"
          Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Grid Grid.Column="0"
              HorizontalAlignment="Left"
              Style="{StaticResource StyleGrid}">
            <TextBlock Text="This is a long colum titel" />
        </Grid>
        <Grid Grid.Column="1"
              HorizontalAlignment="Left"
              Style="{StaticResource StyleGrid}">
            <TextBlock FontSize="11" Text="Bla Bla 12" />
        </Grid>
        <Grid Grid.Column="2"
              HorizontalAlignment="Left"
              Style="{StaticResource StyleGrid}">
            <TextBlock Text="Some more Text" />
        </Grid>
        <Grid Grid.Column="3"
              HorizontalAlignment="Left"
              Style="{StaticResource StyleGrid}">
            <TextBlock Text="Short Text" />
        </Grid>
    </Grid>
</Grid>

Usually when you want the child control to be able to be displayed outside of the bounds of the parent panel, a Canvas is used as the panel. 通常,当您希望子控件能够显示在父面板的边界之外时,可以使用“画布”作为面板。

<Grid VerticalAlignment="Center">
        <Grid.Resources>
            <Style x:Key="StyleGrid2" TargetType="Canvas">
                <Setter Property="VerticalAlignment" Value="Bottom" />
                <Setter Property="HorizontalAlignment" Value="Left" />
                <Setter Property="RenderTransformOrigin" Value="0,0.5" />
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <RotateTransform Angle="330" />
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="24" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="492" />
        </Grid.ColumnDefinitions>

        <!--  Header  -->
        <TextBlock Grid.Row="0"
           Grid.Column="0"
           Grid.ColumnSpan="2"
           FontSize="14"
           FontWeight="Bold"
           Text="Date 14.08.2014" />
        <TextBlock Grid.Row="1"
           Grid.Column="0"
           Margin="1,0,0,0"
           FontSize="18"
           Text="This is the Title" />

        <Grid 
            Grid.Row="0"
            Grid.RowSpan="2"
            ShowGridLines="True"
            Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="60" />
                <ColumnDefinition Width="60" />
                <ColumnDefinition Width="60" />
                <ColumnDefinition Width="60" />
            </Grid.ColumnDefinitions>

            <Canvas Grid.Column="0"
                HorizontalAlignment="Left"
                Style="{StaticResource StyleGrid2}">
                <TextBlock Text="This is a long colum titel" />
            </Canvas>
            <Canvas Grid.Column="1"
                HorizontalAlignment="Left"
                Style="{StaticResource StyleGrid2}">
                <TextBlock FontSize="11" Text="Bla Bla 12" />
            </Canvas>
            <Canvas Grid.Column="2"
                HorizontalAlignment="Left"
                Style="{StaticResource StyleGrid2}">
                <TextBlock Text="Some more Text" />
            </Canvas>
            <Canvas Grid.Column="3"
                HorizontalAlignment="Left"
                Style="{StaticResource StyleGrid2}">
                <TextBlock Text="Short Text" />
            </Canvas>
        </Grid>
    </Grid>

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

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