本文整理汇总了C#中System.Windows.Controls.ItemsControl.ContainerFromElement方法的典型用法代码示例。如果您正苦于以下问题:C# ItemsControl.ContainerFromElement方法的具体用法?C# ItemsControl.ContainerFromElement怎么用?C# ItemsControl.ContainerFromElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ItemsControl
的用法示例。
在下文中一共展示了ItemsControl.ContainerFromElement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DragSource_PreviewMouseLeftButtonDown
private void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_sourceItemsControl = (ItemsControl) sender;
var visual = e.OriginalSource as Visual;
_topWindow = Window.GetWindow(_sourceItemsControl);
_initialMousePosition = e.GetPosition(_topWindow);
_sourceItemContainer = _sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if (_sourceItemContainer != null)
{
_draggedData = _sourceItemContainer.DataContext;
}
}
示例2: ContainerFromElement
public static DependencyObject ContainerFromElement (ItemsControl itemsControl, DependencyObject element)
{
return itemsControl.ContainerFromElement (element);
}
示例3: DragSource_PreviewMouseLeftButtonDown
// DragSource
private void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.sourceItemsControl = (ItemsControl)sender;
Visual visual = e.OriginalSource as Visual;
this.topWindow = Window.GetWindow(this.sourceItemsControl);
this.initialMousePosition = e.GetPosition(this.topWindow);
this.sourceItemContainer = sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if (this.sourceItemContainer != null)
{
//this.draggedData = this.sourceItemContainer.DataContext;
this.draggedData = this.sourceItemContainer; // TODO changed
}
}
示例4: DragSource_PreviewTouchDown
// DragSource Touch
private void DragSource_PreviewTouchDown(object sender, TouchEventArgs e)
{
if (!_ignoreNextTouchDownEvent)
{
this.sourceItemsControl = (ItemsControl)sender;
Visual visual = e.OriginalSource as Visual;
this.topWindow = Window.GetWindow(this.sourceItemsControl);
this.initialMousePosition = e.GetTouchPoint(this.topWindow).Position;
this.sourceItemContainer = sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if (this.sourceItemContainer != null)
{
this.draggedData = this.sourceItemContainer.DataContext;
//Console.WriteLine("preview mouse down, initiate drag");
}
}
else
{
_ignoreNextTouchDownEvent = false;
}
}
示例5: DragSource_PreviewMouseLeftButtonDown
// DragSource
private void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.sourceItemsControl = (ItemsControl)sender;
DependencyObject visual = e.OriginalSource as DependencyObject;
if (visual == null)
return;
this.sourceItemContainer = sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if (this.sourceItemContainer == null)
return;
bool? canDrag = sourceItemContainer.GetValue(DragDrop.DragDropHelper.IsDragAllowedProperty) as bool?;
if (canDrag.HasValue && !canDrag.Value)
return;
this.draggedData = this.sourceItemContainer.DataContext;
this.topWindow = Window.GetWindow(this.sourceItemsControl);
this.initialMousePosition = e.GetPosition(this.topWindow);
}
示例6: dragSource_PreviewMouseLeftButtonDown
private void dragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
sourceItemsControl = (ItemsControl)sender;
Visual visual = e.OriginalSource as Visual;
topWindow = Window.GetWindow(sourceItemsControl);
sourceItemContainer = sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if(sourceItemContainer!=null)
{
draggedData = sourceItemContainer.DataContext;
}
}
示例7: DragSource_PreviewMouseDoubleClick
// DragSource
private void DragSource_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
this._sourceItemsControl = (ItemsControl)sender;
var visual = e.OriginalSource as Visual;
this._sourceItemContainer = _sourceItemsControl.ContainerFromElement(visual) as FrameworkElement;
if (this._sourceItemContainer != null)
{
this._draggedData = this._sourceItemContainer.DataContext;
}
int indexRemoved = RemoveItemFromItemsControl(this._sourceItemsControl, this._draggedData);
Type draggedType = this._draggedData.GetType();
object newitem = Activator.CreateInstance(draggedType);
InsertItemInItemsControl(this._sourceItemsControl, newitem, indexRemoved);
e.Handled = true;
}
示例8: GetGeneratedParentElement
private DependencyObject GetGeneratedParentElement(ItemsControl itemsControl)
{
return itemsControl.ContainerFromElement(this);
}
示例9: DecideDropTarget
private int DecideDropTarget(DragEventArgs e, ItemsControl targetItemsControl)
{
int targetItemsControlCount = targetItemsControl.Items.Count;
DependencyObject targetItemContainer;
int insertionIndex = -1;
if (targetItemsControlCount > 0)
{
targetItemContainer = targetItemsControl.ContainerFromElement((DependencyObject)e.OriginalSource) as FrameworkElement;
if (targetItemContainer != null)
{
insertionIndex = targetItemsControl.ItemContainerGenerator.IndexFromContainer(targetItemContainer);
}
else
{
targetItemContainer = targetItemsControl.ItemContainerGenerator.ContainerFromIndex(targetItemsControlCount - 1) as FrameworkElement;
insertionIndex = targetItemsControlCount;
}
}
else
{
targetItemContainer = null;
insertionIndex = 0;
}
return insertionIndex;
}