当前位置: 首页>>代码示例>>C#>>正文


C# UIElement.SwapWith方法代码示例

本文整理汇总了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;
                    }
                }
            }
        }
开发者ID:EoinF,项目名称:TheOtherDarkWorld,代码行数:50,代码来源:InventoryContainer.cs

示例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;
                    }
                }
            }
        }
开发者ID:EoinF,项目名称:TheOtherDarkWorld,代码行数:31,代码来源:UIContainer.cs


注:本文中的UIElement.SwapWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。