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的TabItem? 滴度M01 滴度M02_Wpf_Tabcontrol - Fatal编程技术网

Wpf 如何移动TabControl的TabItem? 滴度M01 滴度M02

Wpf 如何移动TabControl的TabItem? 滴度M01 滴度M02,wpf,tabcontrol,Wpf,Tabcontrol,我想让TItem01向左移动200像素,然后显示TItem02。 我该怎么办?请帮帮我。多谢各位 不知道这是否是最简单的方法,但我会修改默认的TabControl样式: <Border Background="#FF260F54"> <TabControl Name="MyTabCtrl" SelectionChanged="MyTabCtrl_SelectionChanged" > <TabItem Name="TItem01" Heade

我想让TItem01向左移动200像素,然后显示TItem02。
我该怎么办?请帮帮我。多谢各位

不知道这是否是最简单的方法,但我会修改默认的TabControl样式:

<Border Background="#FF260F54">
    <TabControl Name="MyTabCtrl" SelectionChanged="MyTabCtrl_SelectionChanged" >
        <TabItem Name="TItem01" Header="01">
            <TextBlock>TItem01</TextBlock>
        </TabItem>
        <TabItem Name="TItem02" Header="02">
            <TextBlock>TItem02</TextBlock>
        </TabItem>
    </TabControl>
</Border>

请注意
ContolTemplate
TabPanel
元素的边距属性?该边距确定选项卡的起始位置。默认值为0,0,4,-1,我将其修改为200,0,4,-1以符合您的要求

如果你想知道我是如何制作这种风格的,有几种方法。最简单的方法是使用Expression Blend。它有一个选项可以“断开”控件,并显示所有默认零件和样式。另一种方法是在MSDN中搜索ControlTemplates,因为它们是公共的。(我使用了第二种方法)

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />
<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
<SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />
<Style  TargetType="{x:Type TabControl}">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabControl}">
                <Grid KeyboardNavigation.TabNavigation="Local">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TabPanel 
                        Name="HeaderPanel"
                        Grid.Row="0"
                        Panel.ZIndex="1" 
                        Margin="200,0,4,-1" 
                        IsItemsHost="True"
                        KeyboardNavigation.TabIndex="1"
                        Background="Transparent" />
                    <Border 
                        Name="Border" 
                        Grid.Row="1" 
                        Background="{StaticResource WindowBackgroundBrush}" 
                        BorderBrush="{StaticResource SolidBorderBrush}" 
                        BorderThickness="1" 
                        CornerRadius="2" 
                        KeyboardNavigation.TabNavigation="Local"
                        KeyboardNavigation.DirectionalNavigation="Contained"
                        KeyboardNavigation.TabIndex="2" >
                        <ContentPresenter 
                            Name="PART_SelectedContentHost"
                            Margin="4"
                            ContentSource="SelectedContent" />
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
                        <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>