fixed #196
This commit is contained in:
1 parent
ee9453964b
commit
df8b3e2f49
3 files changed
+97
-21
No files matched your search
@@ -80,16 +80,43 @@ namespace HandyControl.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否显示关闭按钮
|
/// 是否显示关闭按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.RegisterAttached(
|
||||||
"ShowCloseButton", typeof(bool), typeof(TabControl), new PropertyMetadata(ValueBoxes.FalseBox));
|
"ShowCloseButton", typeof(bool), typeof(TabControl), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.Inherits));
|
||||||
|
|
||||||
|
public static void SetShowCloseButton(DependencyObject element, bool value)
|
||||||
|
=> element.SetValue(ShowCloseButtonProperty, value);
|
||||||
|
|
||||||
|
public static bool GetShowCloseButton(DependencyObject element)
|
||||||
|
=> (bool) element.GetValue(ShowCloseButtonProperty);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否显示关闭按钮
|
/// 是否显示关闭按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ShowCloseButton
|
public bool ShowCloseButton
|
||||||
{
|
{
|
||||||
get => (bool)GetValue(ShowCloseButtonProperty);
|
get => GetShowCloseButton(this);
|
||||||
set => SetValue(ShowCloseButtonProperty, value);
|
set => SetShowCloseButton(this, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示上下文菜单
|
||||||
|
/// </summary>
|
||||||
|
public static readonly DependencyProperty ShowContextMenuProperty = DependencyProperty.RegisterAttached(
|
||||||
|
"ShowContextMenu", typeof(bool), typeof(TabControl), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits));
|
||||||
|
|
||||||
|
public static void SetShowContextMenu(DependencyObject element, bool value)
|
||||||
|
=> element.SetValue(ShowContextMenuProperty, value);
|
||||||
|
|
||||||
|
public static bool GetShowContextMenu(DependencyObject element)
|
||||||
|
=> (bool) element.GetValue(ShowContextMenuProperty);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示上下文菜单
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowContextMenu
|
||||||
|
{
|
||||||
|
get => GetShowContextMenu(this);
|
||||||
|
set => SetShowContextMenu(this, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -112,6 +112,57 @@ namespace HandyControl.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示关闭按钮
|
||||||
|
/// </summary>
|
||||||
|
public static readonly DependencyProperty ShowCloseButtonProperty =
|
||||||
|
TabControl.ShowCloseButtonProperty.AddOwner(typeof(TabItem));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示关闭按钮
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowCloseButton
|
||||||
|
{
|
||||||
|
get => (bool)GetValue(ShowCloseButtonProperty);
|
||||||
|
set => SetValue(ShowCloseButtonProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetShowCloseButton(DependencyObject element, bool value)
|
||||||
|
=> element.SetValue(ShowCloseButtonProperty, value);
|
||||||
|
|
||||||
|
public static bool GetShowCloseButton(DependencyObject element)
|
||||||
|
=> (bool)element.GetValue(ShowCloseButtonProperty);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示上下文菜单
|
||||||
|
/// </summary>
|
||||||
|
public static readonly DependencyProperty ShowContextMenuProperty =
|
||||||
|
TabControl.ShowContextMenuProperty.AddOwner(typeof(TabItem));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示上下文菜单
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowContextMenu
|
||||||
|
{
|
||||||
|
get => (bool) GetValue(ShowContextMenuProperty);
|
||||||
|
set => SetValue(ShowContextMenuProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetShowContextMenu(DependencyObject element, bool value)
|
||||||
|
=> element.SetValue(ShowContextMenuProperty, value);
|
||||||
|
|
||||||
|
public static bool GetShowContextMenu(DependencyObject element)
|
||||||
|
=> (bool)element.GetValue(ShowContextMenuProperty);
|
||||||
|
|
||||||
|
public static readonly DependencyProperty MenuProperty = DependencyProperty.Register(
|
||||||
|
"Menu", typeof(ContextMenu), typeof(TabItem), new PropertyMetadata(default(ContextMenu)));
|
||||||
|
|
||||||
|
public ContextMenu Menu
|
||||||
|
{
|
||||||
|
get => (ContextMenu) GetValue(MenuProperty);
|
||||||
|
set => SetValue(MenuProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新选项卡横向偏移
|
/// 更新选项卡横向偏移
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -152,14 +203,10 @@ namespace HandyControl.Controls
|
|||||||
RaiseEvent(argsClosing);
|
RaiseEvent(argsClosing);
|
||||||
if (argsClosing.Cancel) return;
|
if (argsClosing.Cancel) return;
|
||||||
|
|
||||||
if (TabControlParent.IsEnableAnimation)
|
TabPanel.SetCurrentValue(TabPanel.FluidMoveDurationProperty,
|
||||||
{
|
TabControlParent.IsEnableAnimation
|
||||||
TabPanel.SetCurrentValue(TabPanel.FluidMoveDurationProperty, new Duration(TimeSpan.FromMilliseconds(200)));
|
? new Duration(TimeSpan.FromMilliseconds(200))
|
||||||
}
|
: new Duration(TimeSpan.FromMilliseconds(1)));
|
||||||
else
|
|
||||||
{
|
|
||||||
TabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
|
|
||||||
}
|
|
||||||
TabControlParent.IsInternalAction = true;
|
TabControlParent.IsInternalAction = true;
|
||||||
RaiseEvent(new RoutedEventArgs(ClosedEvent, this));
|
RaiseEvent(new RoutedEventArgs(ClosedEvent, this));
|
||||||
TabControlParent.Items.Remove(this);
|
TabControlParent.Items.Remove(this);
|
||||||
|
|||||||
@@ -23,6 +23,15 @@
|
|||||||
<Setter Property="Padding" Value="16,0"/>
|
<Setter Property="Padding" Value="16,0"/>
|
||||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||||
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
|
||||||
|
<Setter Property="Menu">
|
||||||
|
<Setter.Value>
|
||||||
|
<ContextMenu IsEnabled="{Binding ShowContextMenu,RelativeSource={RelativeSource AncestorType=controls:TabItem}}" Visibility="{Binding ShowContextMenu,RelativeSource={RelativeSource AncestorType=controls:TabItem},Converter={StaticResource Boolean2VisibilityConverter}}">
|
||||||
|
<MenuItem Command="interactivity:ControlCommands.Close" Header="{x:Static langs:Lang.Close}"/>
|
||||||
|
<MenuItem Command="interactivity:ControlCommands.CloseAll" Header="{x:Static langs:Lang.CloseAll}"/>
|
||||||
|
<MenuItem Command="interactivity:ControlCommands.CloseOther" Header="{x:Static langs:Lang.CloseOther}"/>
|
||||||
|
</ContextMenu>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
<Setter Property="HeaderTemplate">
|
<Setter Property="HeaderTemplate">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
@@ -33,18 +42,11 @@
|
|||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="controls:TabItem">
|
<ControlTemplate TargetType="controls:TabItem">
|
||||||
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
|
<Grid x:Name="templateRoot" SnapsToDevicePixels="true" ContextMenu="{TemplateBinding Menu}">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Grid.ContextMenu>
|
|
||||||
<ContextMenu>
|
|
||||||
<MenuItem Command="interactivity:ControlCommands.Close" Header="{x:Static langs:Lang.Close}"/>
|
|
||||||
<MenuItem Command="interactivity:ControlCommands.CloseAll" Header="{x:Static langs:Lang.CloseAll}"/>
|
|
||||||
<MenuItem Command="interactivity:ControlCommands.CloseOther" Header="{x:Static langs:Lang.CloseOther}"/>
|
|
||||||
</ContextMenu>
|
|
||||||
</Grid.ContextMenu>
|
|
||||||
<Border Grid.ColumnSpan="2" BorderThickness="{TemplateBinding BorderThickness}" x:Name="mainBorder" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Margin="0">
|
<Border Grid.ColumnSpan="2" BorderThickness="{TemplateBinding BorderThickness}" x:Name="mainBorder" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Margin="0">
|
||||||
<Border Margin="0,0,0,-1" x:Name="innerBorder" Background="{DynamicResource RegionBrush}" Opacity="0"/>
|
<Border Margin="0,0,0,-1" x:Name="innerBorder" Background="{DynamicResource RegionBrush}" Opacity="0"/>
|
||||||
</Border>
|
</Border>
|
||||||
@@ -56,7 +58,7 @@
|
|||||||
</LinearGradientBrush>
|
</LinearGradientBrush>
|
||||||
</ContentPresenter.OpacityMask>
|
</ContentPresenter.OpacityMask>
|
||||||
</ContentPresenter>
|
</ContentPresenter>
|
||||||
<Button Grid.Column="1" Focusable="False" Command="interactivity:ControlCommands.Close" Visibility="{Binding ShowCloseButton,RelativeSource={RelativeSource AncestorType=controls:TabControl},Converter={StaticResource Boolean2VisibilityConverter}}" Background="Transparent" Style="{StaticResource ButtonCustom}" Width="28">
|
<Button Grid.Column="1" Focusable="False" Command="interactivity:ControlCommands.Close" Visibility="{TemplateBinding ShowCloseButton,Converter={StaticResource Boolean2VisibilityConverter}}" Background="Transparent" Style="{StaticResource ButtonCustom}" Width="28">
|
||||||
<Path Fill="{DynamicResource PrimaryTextBrush}" Width="8" Height="8" Style="{StaticResource ClosePathStyle}"/>
|
<Path Fill="{DynamicResource PrimaryTextBrush}" Width="8" Height="8" Style="{StaticResource ClosePathStyle}"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in new issue
Block a user