本文整理汇总了C#中System.Windows.Controls.ListBox.ContainerFromElement方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ContainerFromElement方法的具体用法?C# ListBox.ContainerFromElement怎么用?C# ListBox.ContainerFromElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBox
的用法示例。
在下文中一共展示了ListBox.ContainerFromElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DragDropDown
private void DragDropDown(object sender, MouseButtonEventArgs e)
{
this.sourceBox = (ListBox)sender;
Visual visual = e.OriginalSource as Visual;
this.topWindow = Window.GetWindow(this.sourceBox);
this.startPoint = e.GetPosition(this.topWindow);
this.sourceItem = sourceBox.ContainerFromElement(visual) as ListBoxItem;
if (this.sourceItem != null)
{
this.draggedData = (int)this.sourceItem.DataContext;
}
}
示例2: ListBox_PreviewMouseLeftButtonDown
// Check if Drag & Drop is initiated
private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Handle Doubleclick
if (e.ClickCount > 1)
return;
// Remember DragStartPosition
dragSource = (ListBox) sender;
dragStartPoint = e.GetPosition(dragSource);
// if this element is selected, supress click to allow multiple selections
var listItem = dragSource.ContainerFromElement((Visual) e.OriginalSource) as FrameworkElement;
if (listItem == null)
return;
currentClickedSchüler = dragSource.ItemContainerGenerator.ItemFromContainer(listItem) as Schueler;
if (dragSource.SelectedItems.Contains(currentClickedSchüler))
{
// Prevent further handling to allow Drag and Drop of multi-selections
// Remember to handle it later with DragMoveStarted flag
e.Handled = true;
DragMoveStarted = true;
}
}