本文整理汇总了C#中DesignItem.GetBehavior方法的典型用法代码示例。如果您正苦于以下问题:C# DesignItem.GetBehavior方法的具体用法?C# DesignItem.GetBehavior怎么用?C# DesignItem.GetBehavior使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DesignItem
的用法示例。
在下文中一共展示了DesignItem.GetBehavior方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeContainer
/// <summary>
/// Make the placed item switch the container.
/// This method assumes that you already have checked if changing the container is possible.
/// </summary>
public void ChangeContainer(DesignItem newContainer)
{
if (newContainer == null)
throw new ArgumentNullException("newContainer");
if (isAborted || isCommitted)
throw new InvalidOperationException("The operation is not running anymore.");
if (currentContainer == newContainer)
return;
if (!currentContainerBehavior.CanLeaveContainer(this))
throw new NotSupportedException("The items cannot be removed from their parent container.");
try {
currentContainerBehavior.LeaveContainer(this);
GeneralTransform transform = currentContainer.View.TransformToVisual(newContainer.View);
foreach (PlacementInformation info in placedItems) {
info.OriginalBounds = TransformRectByMiddlePoint(transform, info.OriginalBounds);
info.Bounds = TransformRectByMiddlePoint(transform, info.Bounds).Round();
}
currentContainer = newContainer;
currentContainerBehavior = newContainer.GetBehavior<IPlacementBehavior>();
Debug.Assert(currentContainerBehavior != null);
currentContainerBehavior.EnterContainer(this);
} catch (Exception ex) {
Debug.WriteLine(ex.ToString());
Abort();
throw;
}
}
示例2: TryStartInsertNewComponents
/// <summary>
/// Try to insert new components into the container.
/// </summary>
/// <param name="container">The container that should become the parent of the components.</param>
/// <param name="placedItems">The components to add to the container.</param>
/// <param name="positions">The rectangle specifying the position the element should get.</param>
/// <param name="type">The type </param>
/// <returns>The operation that inserts the new components, or null if inserting is not possible.</returns>
public static PlacementOperation TryStartInsertNewComponents(DesignItem container, IList<DesignItem> placedItems, IList<Rect> positions, PlacementType type)
{
if (container == null)
throw new ArgumentNullException("container");
if (placedItems == null)
throw new ArgumentNullException("placedItems");
if (positions == null)
throw new ArgumentNullException("positions");
if (type == null)
throw new ArgumentNullException("type");
if (placedItems.Count == 0)
throw new ArgumentException("placedItems.Count must be > 0");
if (placedItems.Count != positions.Count)
throw new ArgumentException("positions.Count must be = placedItems.Count");
DesignItem[] items = placedItems.ToArray();
PlacementOperation op = new PlacementOperation(items, type);
try {
for (int i = 0; i < items.Length; i++) {
op.placedItems[i].OriginalBounds = op.placedItems[i].Bounds = positions[i];
}
op.currentContainer = container;
op.currentContainerBehavior = container.GetBehavior<IPlacementBehavior>();
if (op.currentContainerBehavior == null || !op.currentContainerBehavior.CanEnterContainer(op, true)) {
op.changeGroup.Abort();
return null;
}
op.currentContainerBehavior.EnterContainer(op);
} catch (Exception ex) {
Debug.WriteLine(ex.ToString());
op.changeGroup.Abort();
throw;
}
return op;
}