fixed a bug of tabcontrol
This commit is contained in:
1 parent
7171398966
commit
37c9f3e3af
3 files changed
+17
-20
No files matched your search
@@ -155,6 +155,7 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
item.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
item.IsSelected = true;
|
item.IsSelected = true;
|
||||||
|
item.TabPanel = _headerPanel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IsInternalAction = false;
|
IsInternalAction = false;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace HandyControl.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标签容器
|
/// 标签容器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private TabPanel _tabPanel;
|
internal TabPanel TabPanel { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前编号
|
/// 当前编号
|
||||||
@@ -108,8 +108,6 @@ namespace HandyControl.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isLoaded;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新选项卡横向偏移
|
/// 更新选项卡横向偏移
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -117,23 +115,17 @@ namespace HandyControl.Controls
|
|||||||
private void UpdateItemOffsetX(int oldIndex)
|
private void UpdateItemOffsetX(int oldIndex)
|
||||||
{
|
{
|
||||||
if (!_isDragging) return;
|
if (!_isDragging) return;
|
||||||
var moveItem = _tabPanel.ItemDic[CurrentIndex];
|
var moveItem = TabPanel.ItemDic[CurrentIndex];
|
||||||
moveItem.CurrentIndex -= CurrentIndex - oldIndex;
|
moveItem.CurrentIndex -= CurrentIndex - oldIndex;
|
||||||
var offsetX = moveItem.TargetOffsetX;
|
var offsetX = moveItem.TargetOffsetX;
|
||||||
var resultX = offsetX + (oldIndex - CurrentIndex) * ItemWidth;
|
var resultX = offsetX + (oldIndex - CurrentIndex) * ItemWidth;
|
||||||
_tabPanel.ItemDic[CurrentIndex] = this;
|
TabPanel.ItemDic[CurrentIndex] = this;
|
||||||
_tabPanel.ItemDic[moveItem.CurrentIndex] = moveItem;
|
TabPanel.ItemDic[moveItem.CurrentIndex] = moveItem;
|
||||||
moveItem.CreateAnimation(offsetX, resultX);
|
moveItem.CreateAnimation(offsetX, resultX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TabItem()
|
public TabItem()
|
||||||
{
|
{
|
||||||
Loaded += (s, e) =>
|
|
||||||
{
|
|
||||||
if (_isLoaded) return;
|
|
||||||
_tabPanel = VisualParent as TabPanel;
|
|
||||||
_isLoaded = true;
|
|
||||||
};
|
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, Close));
|
CommandBindings.Add(new CommandBinding(ControlCommands.Close, Close));
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll, (s, e) =>
|
CommandBindings.Add(new CommandBinding(ControlCommands.CloseAll, (s, e) =>
|
||||||
{
|
{
|
||||||
@@ -172,11 +164,11 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
if (TabControlParent.IsEnableAnimation)
|
if (TabControlParent.IsEnableAnimation)
|
||||||
{
|
{
|
||||||
_tabPanel.ClearValue(TabPanel.FluidMoveDurationProperty);
|
TabPanel.ClearValue(TabPanel.FluidMoveDurationProperty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
|
TabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
|
||||||
}
|
}
|
||||||
TabControlParent.IsInternalAction = true;
|
TabControlParent.IsInternalAction = true;
|
||||||
TabControlParent.Items.Remove(this);
|
TabControlParent.Items.Remove(this);
|
||||||
@@ -187,7 +179,7 @@ namespace HandyControl.Controls
|
|||||||
base.OnMouseLeftButtonDown(e);
|
base.OnMouseLeftButtonDown(e);
|
||||||
if (TabControlParent.IsDraggable && !ItemIsDragging && !_isDragging)
|
if (TabControlParent.IsDraggable && !ItemIsDragging && !_isDragging)
|
||||||
{
|
{
|
||||||
_tabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
|
TabPanel.FluidMoveDuration = new Duration(TimeSpan.FromSeconds(0));
|
||||||
_mouseDownOffsetX = RenderTransform.Value.OffsetX;
|
_mouseDownOffsetX = RenderTransform.Value.OffsetX;
|
||||||
var mx = TranslatePoint(new Point(), TabControlParent).X;
|
var mx = TranslatePoint(new Point(), TabControlParent).X;
|
||||||
_mouseDownIndex = CalLocationIndex(mx);
|
_mouseDownIndex = CalLocationIndex(mx);
|
||||||
@@ -259,15 +251,15 @@ namespace HandyControl.Controls
|
|||||||
RenderTransform = new TranslateTransform(resultX, 0);
|
RenderTransform = new TranslateTransform(resultX, 0);
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
var parent = TabControlParent;
|
var parent = TabControlParent;
|
||||||
_tabPanel.CanUpdate = false;
|
TabPanel.CanUpdate = false;
|
||||||
parent.IsInternalAction = true;
|
parent.IsInternalAction = true;
|
||||||
parent.Items.Remove(this);
|
parent.Items.Remove(this);
|
||||||
parent.IsInternalAction = true;
|
parent.IsInternalAction = true;
|
||||||
parent.Items.Insert(index, this);
|
parent.Items.Insert(index, this);
|
||||||
_tabPanel.CanUpdate = true;
|
TabPanel.CanUpdate = true;
|
||||||
_tabPanel.ForceUpdate = true;
|
TabPanel.ForceUpdate = true;
|
||||||
_tabPanel.Measure(new Size(_tabPanel.DesiredSize.Width, ActualHeight));
|
TabPanel.Measure(new Size(TabPanel.DesiredSize.Width, ActualHeight));
|
||||||
_tabPanel.ForceUpdate = false;
|
TabPanel.ForceUpdate = false;
|
||||||
Focus();
|
Focus();
|
||||||
IsSelected = true;
|
IsSelected = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,10 @@ namespace HandyControl.Controls
|
|||||||
ForceUpdate = true;
|
ForceUpdate = true;
|
||||||
Measure(new Size(DesiredSize.Width, ActualHeight));
|
Measure(new Size(DesiredSize.Width, ActualHeight));
|
||||||
ForceUpdate = false;
|
ForceUpdate = false;
|
||||||
|
foreach (var item in ItemDic.Values)
|
||||||
|
{
|
||||||
|
item.TabPanel = this;
|
||||||
|
}
|
||||||
_isLoaded = true;
|
_isLoaded = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user