WPF:更改HeaderedContentControl方向

时间:2013-12-02 17:35:01

标签: wpf orientation

有没有办法在HeaderedContentControl中更改标题和内容的方向? 这就是我需要做的事情: enter image description here

有人可以帮我一把吗?

2 个答案:

答案 0 :(得分:1)

您可以创建一个UserControl,其内容类似于以下内容:

在UC内部(或任何您希望将其包装的模板或方式):

 <Grid>
    <Grid.ColumnDefinitions>
         <ColumnDefinition Width="Auto"/>
         <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <Grid Background="Green">
        <TextBlock Text="Some Title" Background="Transparent" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center">
            <TextBlock.LayoutTransform>
                <RotateTransform Angle="-90"/>          
            </TextBlock.LayoutTransform>                        
        </TextBlock>        
    </Grid>

    <ContentControl Grid.Column="1">
        <ContentControl.Content>
            <Rectangle Fill="Red" />    <!-- Or Any Content you may desire -->      
        </ContentControl.Content>
    </ContentControl>   
</Grid>

答案 1 :(得分:0)

enter image description here

我只是通过使用网格来解决它,就像每个人一样! 我创建了一个包含多个列的网格,并且我将第一列用作标题。正如你所看到的,我不得不使用RenderTransform旋转文本,但我看起来很好。 我知道这并没有回答HeaderedContentControl的真实问题,但我的任务是解决方案。 这是我的XAML:

<Grid >
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.05*"/>
            <ColumnDefinition Width="0.15*"/>
            <ColumnDefinition Width="0.15*"/>
            <ColumnDefinition Width="0.15*"/>
            <ColumnDefinition Width="0.15*"/>
            <ColumnDefinition Width="0.15*"/>
        </Grid.ColumnDefinitions>
        <Grid Column="0" Background="#009999">
            <TextBlock Grid.Column="0" Text="{Binding Strand.Description,FallbackValue='Strand X'}" FontSize="18"
                       Foreground="White" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 30">
                <TextBlock.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                </TextBlock.LayoutTransform>
            </TextBlock>
        </Grid>

        <Grid Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.55*"/>
                    <ColumnDefinition Width="0.45*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Style="{StaticResource SubHeader}" Text="{x:Static Localization:LanguageResource.Variables}" TextAlignment="Center"/>
                <TextBlock Grid.Row="1" Style="{StaticResource GridKeyCell}" Text="{x:Static Localization:LanguageResource.OperationMode}"/>
                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding FALTA,FallbackValue='---'}" MinWidth="50" TextAlignment="Center" Style="{StaticResource GridValueCellHighRelevance}"/>

                <TextBlock Grid.Row="2" Style="{StaticResource GridKeyCell}" Text="{x:Static Localization:LanguageResource.Speed}"/>
                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding FALTA,FallbackValue='---'}" MinWidth="50" TextAlignment="Center" Style="{StaticResource GridValueCell}"/>

                <TextBlock Grid.Row="3" Style="{StaticResource GridKeyCell}" Text="{x:Static Localization:LanguageResource.Direction}"/>
                <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding FALTA,FallbackValue='---'}" MinWidth="50" TextAlignment="Center" Style="{StaticResource GridValueCell}"/>

                <TextBlock Grid.Row="4" Style="{StaticResource GridKeyCell}"/>
                <TextBlock Grid.Row="4" Grid.Column="1" MinWidth="50" TextAlignment="Center" Style="{StaticResource GridValueCell}"/>
            </Grid>
        </Grid>

        <Grid Column="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                    <RowDefinition Height="0.25*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.55*"/>
                    <ColumnDefinition Width="0.15*"/>
                    <ColumnDefinition Width="0.30*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Grid.Row="1" Grid.RowSpan="4" Source="../Style/Images/Withdrawal - DummyBar.png" Stretch="Fill" Height="105" Width="45"></Image>

                <TextBlock Grid.Row="0" Grid.ColumnSpan="3" Style="{StaticResource SubHeader}" Text="{x:Static Localization:LanguageResource.Machine4}" TextAlignment="Center"/>

                <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Style="{StaticResource GridKeyCell}" Text="{x:Static Localization:LanguageResource.PressurePSI}"/>
                <TextBlock Grid.Row="2" Grid.Column="1" Style="{StaticResource GridValueCell}" Text="{Binding FALTA,FallbackValue='---'}"/>
                <TextBlock Grid.Row="2" Grid.Column="2" Style="{StaticResource GridValueCell}" Text="{Binding FALTA,FallbackValue='---'}"/>

                <TextBlock Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2"  Style="{StaticResource GridKeyCell}" Text="{x:Static Localization:LanguageResource.Current}"/>
                <TextBlock Grid.Row="4" Grid.Column="1" Style="{StaticResource GridValueCell}" Text="{Binding FALTA,FallbackValue='---'}"/>
                <TextBlock Grid.Row="4" Grid.Column="2" Style="{StaticResource GridValueCell}" Text="{Binding FALTA,FallbackValue='---'}"/>

            </Grid>
        </Grid>            
    </Grid>

我没有绑定数据...在哪里说“FALTA”你只读了你想要的任何属性。 谢谢大家的答案!