Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 需要一些关于如何设置自定义tabcontrol的建议吗_Wpf_Xaml_Tabcontrol - Fatal编程技术网

Wpf 需要一些关于如何设置自定义tabcontrol的建议吗

Wpf 需要一些关于如何设置自定义tabcontrol的建议吗,wpf,xaml,tabcontrol,Wpf,Xaml,Tabcontrol,如何使tabitem(标题)边框与内容部分对齐。下面我将项目标题放在网格中。我附上了一张照片。左边有一些小空间。顶部也是一样。我想把它填满 <Grid> <TabControl Margin="10" BorderThickness="2" Background="LightGray" Padding="0"> <TabControl.Resources> <Style Target

如何使tabitem(标题)边框与内容部分对齐。下面我将项目标题放在网格中。我附上了一张照片。左边有一些小空间。顶部也是一样。我想把它填满

<Grid>
    <TabControl Margin="10" BorderThickness="2" Background="LightGray" Padding="0">            
        <TabControl.Resources>
            <Style TargetType="TabItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TabItem">
                            <Grid Name="Panel">
                                <ContentPresenter x:Name="ContentSite" 
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Center"
                                    ContentSource="Header"
                                    Margin="30,3"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" />
                                </Trigger>
                                <Trigger Property="IsSelected" Value="False">
                                    <Setter TargetName="Panel" Property="Background" Value="White" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </TabControl.Resources>

        <TabItem Header="General">
            <Label Content="Content goes here..." />
        </TabItem>
        <TabItem Header="Security" />
        <TabItem Header="Details" />
    </TabControl>
</Grid>


设置TabItem而不是Tab的边距

<TabItem Header="General", Margin="0,0,0,0"/>


将TabItem的边距设置为0,这将覆盖默认边距并按照您的要求工作

TabItem的默认模板边距为-1,但在您的情况下,边框厚度设置为2。所以-2的保证金应该对你有用

设置网格上的边距:

<ControlTemplate TargetType="TabItem">
    <Grid Name="Panel" Margin="-2,-2,-2,0">
        <ContentPresenter x:Name="ContentSite" 
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        ContentSource="Header"
                        Margin="30,3"/>
    </Grid>
    .....

.....