如何将TabControl标头的文本向左对齐?

时间:2019-07-19 01:20:19

标签: c# wpf header tabcontrol

我已经尝试过Horizo​​ntalAligenment Left,但是它不起作用,StackPanel仍然在中心。

<TabControl x:Name="ControlTC" Grid.Row="1" HorizontalAlignment="Stretch" Margin="0,0,5,5"  VerticalAlignment="Stretch" SelectionChanged="ControlTC_SelectionChanged" >
            <TabControl.Resources>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="FontFamily" Value="Yu Gothic UI Semibold"/>
                    <Setter Property="FontSize" Value="13"/>
                    <Setter Property="Foreground" Value="Black"/>
                    <Setter Property="HorizontalAlignment" Value="Left"/>
                </Style>
            </TabControl.Resources>
            <TabItem>
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal" >
                        <Image Name="DeviceInfo" VerticalAlignment="Center" Width="20" Height="20"/>
                        <TextBlock Text="DeviceInfo" VerticalAlignment="Center" Margin="6,0,0,0" FontSize="13" FontFamily="Noto Sans Mono CJK KR Bold"/>
                    </StackPanel>
                </TabItem.Header>
                <Grid Background="#FFFFFFFF">
                    <cr:ElectricSignPanel x:Name="ElectricSign"></cr:ElectricSignPanel>
                </Grid>
            </TabItem>
        </TabControl>

1 个答案:

答案 0 :(得分:0)

这可能有帮助

<TabControl TabStripPlacement="Left" HorizontalContentAlignment="Left" >
        <TabItem HorizontalAlignment="Left" HorizontalContentAlignment="Left" Header="Header 1">
            <TabItem.Content>
                  Test
            </TabItem.Content>
       </TabItem>
</TabControl>