本文整理汇总了C#中UIElement.SwapWith方法的典型用法代码示例。如果您正苦于以下问题:C# UIElement.SwapWith方法的具体用法?C# UIElement.SwapWith怎么用?C# UIElement.SwapWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIElement
的用法示例。
在下文中一共展示了UIElement.SwapWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwapChildren
public override void SwapChildren(UIElement e1, UIElement e2)
{
Item[] binding = DataBinding as Item[];
int i1 = Children.IndexOf(e1);
int i2 = Children.IndexOf(e2);
if (i1 == -1 || i2 == -1)
{
//
// At least one of the child elements don't exist in this container
// so check higher up
//
if (this.Parent != null)
(this.Parent as UIContainer).SwapChildren(e1.Parent, e2.Parent);
}
else
{
if (binding[i1] != null && binding[i2] != null
&& binding[i1].Type == binding[i2].Type)
{
int amountMissing = binding[i1].MaxAmount - binding[i1].Amount;
if (amountMissing > 0)
{
if (binding[i2].Amount > amountMissing) //If we have more than enough to fill the missing amount
{
binding[i1].Amount = binding[i1].MaxAmount;
binding[i2].Amount -= amountMissing;
}
else //We don't have enough to fill up the missing amount
{
binding[i1].Amount += binding[i2].Amount;
binding[i2].Amount = 0;
}
}
}
else if (e1.SwapWith(e2)) //If they actually swap
{
UIElement tempEl = Children[i1];
Children[i1] = Children[i2];
Children[i2] = tempEl;
if (i1 < DataBinding.Length && i2 < DataBinding.Length)
{
var tempobj = DataBinding[i1];
DataBinding[i1] = DataBinding[i2];
DataBinding[i2] = tempobj;
}
}
}
}
示例2: SwapChildren
public virtual void SwapChildren(UIElement e1, UIElement e2)
{
int i1 = Children.IndexOf(e1);
int i2 = Children.IndexOf(e2);
if (i1 == -1 || i2 == -1)
{
//
// At least one of the child elements don't exist in this container
// so check higher up
//
if (this.Parent != null)
(this.Parent as UIContainer).SwapChildren(e1.Parent, e2.Parent);
}
else
{
if (e1.SwapWith(e2)) //If they actually swap
{
UIElement tempEl = Children[i1];
Children[i1] = Children[i2];
Children[i2] = tempEl;
if (i1 < DataBinding.Length && i2 < DataBinding.Length)
{
var tempobj = DataBinding[i1];
DataBinding[i1] = DataBinding[i2];
DataBinding[i2] = tempobj;
}
}
}
}