Gong-wpf-dragdrop: After I overwrote TabControl style, so drag-and-drop won't work (TabControl重写样式后不支持拖拽)

Created on 28 Nov 2018  ·  3Comments  ·  Source: punker76/gong-wpf-dragdrop

我重写了TabControl后,拖拽不能使用了。
样式中我没使用TabPanel,因为我不希望TabItem标题换行,这样做了后拖拽不能使用了
After I overwrote TabControl, drag-and-drop is no longer available
I didn't use TabPanel in the style, because I didn't want the TabItem header to wrap, so drag-and-drop won't work

    <Style x:Key="DefaultTabControl" TargetType="{x:Type TabControl}">
        <Setter Property="Padding" Value="5 0 5 0"/>
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource ControlBorderBrush}" />
        <Setter Property="ItemContainerStyle" Value="{DynamicResource FIconTabItemStyle}"/>
        <Setter Property="TabStripPlacement" Value="Top"/>
        <Setter Property="Panel.ZIndex" Value="3"/>
        <Setter Property="local:ControlAttachProperty.HeaderHeight" Value="20"/>
        <Setter Property="local:ControlAttachProperty.FocusBackground" Value="{StaticResource ButtonPressedBackground}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid x:Name="PART_Root" Margin="{TemplateBinding Margin}" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="col1" Width="Auto"/>
                            <ColumnDefinition x:Name="col2" Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="row1" Height="Auto"/>
                            <RowDefinition x:Name="row2" Height="*"/>
                        </Grid.RowDefinitions>

                        <!--这里我没使用TabPanel,因为我不希望TabItem标题换行-->
                        <!--I'm not using a TabPanel here, because I don't want the TabItem header to wrap-->
                        <Grid x:Name="PART_Header">
                            <Border x:Name="PART_HeaderBorder" BorderBrush="{TemplateBinding local:ControlAttachProperty.FocusBackground}" 
                                    BorderThickness="0,0,0,2" Panel.ZIndex="{TemplateBinding Panel.ZIndex}"/>
                            <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled" Margin="{TemplateBinding Padding}" Panel.ZIndex="2" >
                                <StackPanel x:Name="PART_HeaderPanel" Orientation="Vertical" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        IsItemsHost="True" MinHeight="{TemplateBinding local:ControlAttachProperty.HeaderHeight}"/>
                            </ScrollViewer>
                        </Grid>

                        <Border x:Name="PART_ContentPanel" Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
                                    KeyboardNavigation.DirectionalNavigation="Contained" KeyboardNavigation.TabIndex="2" 
                                    KeyboardNavigation.TabNavigation="Local" Width="Auto">
                            <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Width="Auto"/>
                        </Border>
                    </Grid>
Bug

Most helpful comment

Hey, i had same issue. Quick fix is to wrap your ContentPresenter to AdornerDecorator.

All 3 comments

@kwonganding Can you please create a short sample which shows your issue? thx

short sample:
dragdrop-test.zip

Hey, i had same issue. Quick fix is to wrap your ContentPresenter to AdornerDecorator.

Was this page helpful?
0 / 5 - 0 ratings