本文整理汇总了C#中ModelItem.IsItemOfType方法的典型用法代码示例。如果您正苦于以下问题:C# ModelItem.IsItemOfType方法的具体用法?C# ModelItem.IsItemOfType怎么用?C# ModelItem.IsItemOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelItem
的用法示例。
在下文中一共展示了ModelItem.IsItemOfType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Activate
/// <summary>
/// When this TabItem is activated set IsSelected to true.
/// </summary>
/// <param name="item">A ModelItem representing the adorned element.</param>
protected override void Activate(ModelItem item)
{
if (item != null && item.IsItemOfType(MyPlatformTypes.TabItem.TypeId))
{
if (Context != null)
{
Tool tool = Context.Items.GetValue<Tool>();
if (tool == null || tool.FocusedTask == null)
{
TabItemDesignModeValueProvider.SetDesignTimeIsSelected(item, true); // activate the tab that has been selected
item.View.UpdateLayout();
}
}
}
base.Activate(item);
}
示例2: RedirectParent
/// <summary>
/// Determine how the control is parented into the TabItem.
/// If the control is a TabItem then parent it to the TabControl rather
/// than the TabItem (think select, copy, paste a TabItem).
/// If the TabItem has content and the content can accept children
/// then parent into that and so on.
/// </summary>
/// <param name="parent">The parent item.</param>
/// <param name="childType">The type of child item.</param>
/// <returns>Redirected parent.</returns>
public override ModelItem RedirectParent(ModelItem parent, Type childType)
{
_canParent = true;
if (parent == null)
{
throw new ArgumentNullException("parent");
}
if (childType == null)
{
throw new ArgumentNullException("childType");
}
// if the tabItem is not activated and/or not within TabControl,
// redirect to its parent by returning ourselves.
if (parent.IsItemOfType(MyPlatformTypes.TabItem.TypeId)
&& parent.Parent != null
&& (!parent.Parent.IsItemOfType(MyPlatformTypes.TabControl.TypeId) || !TabItemDesignModeValueProvider.GetDesignTimeIsSelected(parent)))
{
_canParent = false;
return parent;
}
// if element being parented is tabItem then add it as sibling of
// existing tabItems inside TabControl - redirect to parent;
// else parent this control in TabItem's content, if its Panel.
if (ModelFactory.ResolveType(parent.Context, MyPlatformTypes.TabItem.TypeId).IsAssignableFrom(childType))
{
_canParent = false;
return parent;
}
if (parent.Content != null && parent.Content.IsSet)
{
// if TabItem has a content and if the content is a panel or a contentcontrol,
// let the content act as the parent.
ModelItem content = parent.Content.Value;
if (content != null)
{
ViewItem contentView = content.View;
if (content.View != null)
{
// if the content is not visible but the tabItem is selected,
// Update this TabItems Layout.
if (!contentView.IsVisible && TabItemDesignModeValueProvider.GetDesignTimeIsSelected(parent))
{
parent.View.UpdateLayout();
}
if (contentView.IsVisible &&
(content.IsItemOfType(MyPlatformTypes.Panel.TypeId) || content.IsItemOfType(MyPlatformTypes.ContentControl.TypeId)))
{
return content;
}
}
else
{
// TabItem has a content already but the content cannot accept parenting right now
// so let tabItem's parent take care of parenting.
_canParent = false;
return parent;
}
}
}
// TabItem doesnt have any content and now tabItem itself acts as the parent.
return base.RedirectParent(parent, childType);
}
示例3: CanParent
/// <summary>
/// Determines whether an item may be dragged inside this panel.
/// </summary>
/// <param name="parent">The panel.</param>
/// <param name="childType">The child.</param>
/// <returns>True if the item may be parented.</returns>
public override bool CanParent(ModelItem parent, Type childType)
{
if (parent == null)
{
throw new ArgumentNullException("parent");
}
if (childType == null)
{
throw new ArgumentNullException("childType");
}
return parent.IsItemOfType(_targetPanelType);
}
示例4: OnBeforeRemove
/// <summary>
/// Called before remove.
/// </summary>
/// <param name="currentParent">The current parent.</param>
/// <param name="newParent">The new parent.</param>
/// <param name="child">The child being re-parented.</param>
protected virtual void OnBeforeRemove(ModelItem currentParent, ModelItem newParent, ModelItem child)
{
if (currentParent == null)
{
throw new ArgumentNullException("currentParent");
}
if (newParent == null)
{
throw new ArgumentNullException("newParent");
}
if (child == null)
{
throw new ArgumentNullException("child");
}
// Remove canvas properties if our new parent is not the same kind of panel
if (!newParent.IsItemOfType(_targetPanelType))
{
foreach (PropertyIdentifier prop in ContainerSpecificProperties)
{
ModelProperty property = child.Properties.Find(prop);
if (property != null)
{
property.ClearValue();
}
}
}
}
示例5: Parent
/// <summary>
/// Parent the given control into the TabControl.
/// </summary>
/// <param name="parent">The new parent item for child.</param>
/// <param name="child">The child item.</param>
public override void Parent(ModelItem parent, ModelItem child)
{
if (parent == null)
{
throw new ArgumentNullException("parent");
}
if (child == null)
{
throw new ArgumentNullException("child");
}
// Clear existing property values that we don't want to apply to the new container.
child.Properties[MyPlatformTypes.FrameworkElement.MarginProperty].ClearValue();
child.Properties[MyPlatformTypes.FrameworkElement.HorizontalAlignmentProperty].ClearValue();
child.Properties[MyPlatformTypes.FrameworkElement.VerticalAlignmentProperty].ClearValue();
bool childIsTabItem = child.IsItemOfType(MyPlatformTypes.TabItem.TypeId);
// We always accept parenting in TabControl if there is not active focused Task.
// If the control being pasted is not TabItem and TabControl is empty (doesnt have any TabItem(s) in it)
// then we inject a TabItem with Grid in TabControl and paste the control under consideration in TabItem.
// We inject a TabItem also in cases when active TabItem is not capable of parenting concerned control
if (!childIsTabItem)
{
// Based on evaluation done in RedirectParent(),
// if any control other than TabItem is being parented to Control in this Parent() call
// then we need to add a new Tabitem with Grid in it
try
{
ModelItem newTabItem = ModelFactory.CreateItem(parent.Context, MyPlatformTypes.TabItem.TypeId, CreateOptions.InitializeDefaults);
parent.Content.Collection.Add(newTabItem);
// activate the newly added tabItem
TabItemDesignModeValueProvider.SetDesignTimeIsSelected(newTabItem, true);
int index = parent.Content.Collection.Count - 1;
// Find a suitable parent for control to be pasted.
// Since we always accept parenting for TabControl when there is no active focused task,
// we better make sure this works.
AdapterService adapterService = parent.Context.Services.GetService<AdapterService>();
if (adapterService != null)
{
ModelItem targetParent = FindSuitableParent(adapterService, parent, child.ItemType, index);
if (targetParent != null)
{
ParentAdapter parentAdapter = adapterService.GetAdapter<ParentAdapter>(targetParent.ItemType);
parentAdapter.Parent(targetParent, child);
}
else
{
Debug.Assert(targetParent != null, "Parenting failed!");
}
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Parenting Failed", ex.InnerException);
}
}
else
{
// child being added is a TabItem;
child.Properties[MyPlatformTypes.TabItem.IsSelectedProperty].ClearValue();
parent.Content.Collection.Add(child);
TabItemDesignModeValueProvider.SetDesignTimeIsSelected(child, true); // Activate the newly added tabItem
}
}
示例6: RemoveParent
/// <summary>
/// Called when removing.
/// </summary>
/// <param name="currentParent">The current parent.</param>
/// <param name="newParent">The new parent.</param>
/// <param name="child">The child being re-parented.</param>
public override void RemoveParent(ModelItem currentParent, ModelItem newParent, ModelItem child)
{
if (currentParent == null)
{
throw new ArgumentNullException("currentParent");
}
if (newParent == null)
{
throw new ArgumentNullException("newParent");
}
if (child == null)
{
throw new ArgumentNullException("child");
}
if (currentParent.Content.Value == child)
{
currentParent.Content.ClearValue();
}
else
{
if (currentParent.IsItemOfType(PlatformTypes.HeaderedContentControl.TypeId) &&
currentParent.Properties[PlatformTypes.HeaderedContentControl.HeaderProperty].Value == child)
{
currentParent.Properties[PlatformTypes.HeaderedContentControl.HeaderProperty].ClearValue(); // clear the header property.
}
}
}
示例7: GetColumnStringType
/// <summary>
/// Returns the string that represents a given DataGridColumn type
/// </summary>
internal static string GetColumnStringType(ModelItem column)
{
if (column.IsItemOfType(PlatformTypes.DataGridTextColumn.TypeId))
{
return Properties.Resources.Text_Column;
}
if (column.IsItemOfType(PlatformTypes.DataGridCheckBoxColumn.TypeId))
{
return Properties.Resources.CheckBox_Column;
}
if (column.IsItemOfType(PlatformTypes.DataGridTemplateColumn.TypeId))
{
return Properties.Resources.Template_Column;
}
return string.Empty;
}