WPF:在WPF和C#中使用TabControl的TabItem标头样式

时间:2018-09-20 06:44:44

标签: wpf xaml header styles tabcontrol

我是WPF的新手, 我正在尝试设置TabControl的样式,但无法设置实际的TabItem的样式:

enter image description here

我相信这可能并不难,但我只是想不通,所以我们将不胜感激!

到目前为止,这是TabControl的XAML:

 <Window x:Class="FunctionalFun.UI.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:gc="clr-namespace:FunctionalFun.UI"
            mc:Ignorable="d"
            Title="mY Application" Height="800" Width="1080" ResizeMode="NoResize">
        <StackPanel>
            <Grid>
                <TabControl Name="TabControl1" TabStripPlacement="Left" Margin="-6,46,-14,-453">
                    <TabItem>
                        <TabItem.Header>
                            <Image Height="35" Width="35" Source="check-form_logo3.png"/>
                        </TabItem.Header>
<TabItem.Resources>
                            <Style TargetType="{x:Type Border}">
                                <Setter Property="CornerRadius" Value="10"/>
                            </Style>
                        </TabItem.Resources>
                        <Canvas>

                        </Canvas>

                    </TabItem>

                    <TabItem >
                        <TabItem.Header>
                            <Image Height="35" Width="35" Source="calendar-icon_logo1.png"/>
                        </TabItem.Header>
                        <TabItem.Resources>
                            <Style TargetType="{x:Type Border}">
                                <Setter Property="CornerRadius" Value="10"/>
                            </Style>
                        </TabItem.Resources>
                        <Canvas>


                        </Canvas>

                    </TabItem>

                    <TabItem >
                        <TabItem.Header>
                            <Image Width="35" Height="35" Source="table_logo4.png"/>
                        </TabItem.Header>
                        <Canvas>
                        </Canvas>
                    </TabItem>
                </TabControl>
            </Grid>
        </StackPanel>
    </Window>

1 个答案:

答案 0 :(得分:0)

一种选择是复制选项卡项目的默认样式,然后更改其边框角半径,背景等,然后为其赋予一个键,然后将样式应用于实际控件,如下所示:

{
  "name": "projects/project_name/metricDescriptors/custom.googleapis.com/folder/completesolar",
  "metricKind": "GAUGE",
  "valueType": "DOUBLE",
  "unit": "By",
  "description": "Folder bytes used",
  "displayName": "Folder usage",
  "type": "custom.googleapis.com/folder/completesolar",
  "metadata": {
    "launchStage": "GA",
    "samplePeriod": "60s",
    "ingestDelay": "0s"
    }
}

enter image description here