本文整理汇总了C#中System.Windows.Controls.ListBox.ScrollIntoViewIndex方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ScrollIntoViewIndex方法的具体用法?C# ListBox.ScrollIntoViewIndex怎么用?C# ListBox.ScrollIntoViewIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBox
的用法示例。
在下文中一共展示了ListBox.ScrollIntoViewIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sourceBoxAllowKeyAction
public void sourceBoxAllowKeyAction(ListBox box, KeyEventHandler add_handler = null)
{
if (box == null) return;
//
box.PreviewKeyDown += new KeyEventHandler((sender, e) =>
{
if (Keyboard.Modifiers != ModifierKeys.None) return;
//
switch (e.Key)
{
case Key.Enter:
(add_handler ?? button_Add_Click)(sender, e);
//一つ下へ移動する。ただし、カーソル位置は正しく動かない。
int pos = box.SelectedIndex + 1;
box.SelectedIndex = Math.Max(0, Math.Min(pos, box.Items.Count - 1));
box.ScrollIntoViewIndex(box.SelectedIndex);
e.Handled = true;
break;
}
});
}
示例2: bxDeleteItems
/// <summary>選択アイテム削除</summary>
public bool bxDeleteItems(ListBox box, IList boxItemsSource = null)
{
try
{
if (box == null || box.SelectedIndex < 0) return false;
var boxItems = boxItemsSource ?? box.Items;
int newSelectedIndex = -1;
while (box.SelectedIndex >= 0)
{
newSelectedIndex = box.SelectedIndex;
boxItems.RemoveAt(newSelectedIndex);
TargetBoxItemsRefresh(box, boxItemsSource);
}
if (box.Items.Count != 0)
{
box.SelectedIndex = Math.Min(newSelectedIndex, box.Items.Count - 1);
box.ScrollIntoViewIndex(box.SelectedIndex);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
return true;
}
示例3: bxMoveItemsDrop
/// <summary>アイテムをボックス内にドロップ</summary>
public bool bxMoveItemsDrop(ListBox box, object dropTo, IList boxItemsSource = null)
{
try
{
if (box == null || box.SelectedIndex < 0) return false;
var boxItems = boxItemsSource ?? box.Items;
//選択の上と下でドロップ位置を調整する。
int idx_dropTo = boxItems.IndexOf(dropTo);
idx_dropTo = idx_dropTo < 0 ? boxItems.Count : idx_dropTo;
idx_dropTo += (idx_dropTo >= box.SelectedIndex ? 1 : 0);
var selected = box.SelectedItemsList(true);
var insertItem = boxItems.Cast<object>().Skip(idx_dropTo).FirstOrDefault(item => !selected.Contains(item));
boxItems.RemoveItemsAx(selected);//削除はこのタイミング
int insertIdx = insertItem == null ? boxItems.Count : boxItems.IndexOf(insertItem);
boxItems.InsertItemsAx(insertIdx, selected);
box.SelectedItemsAdd(selected);
TargetBoxItemsRefresh(box, boxItemsSource);
box.ScrollIntoViewIndex(insertItem == null ? int.MaxValue : box.SelectedIndex);
}
catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
return true;
}
示例4: bxAddItems
/// <summary>選択アイテム追加・挿入</summary>
public bool bxAddItems(IEnumerable srcList, ListBox target, bool IsInsert = false, IList trgItemsSource = null)
{
try
{
if (srcList == null || srcList.Cast<object>().Count() == 0 || target == null) return false;
var trgItems = trgItemsSource ?? target.Items;
var addList = srcList.Cast<object>()
.Where(item => IsEnableDuplicate(item) == true || bxContains(target.Items, item) == false)
.Select(item => IsEnableDuplicate(item) == true ? CloneObj(item) : item).ToList();
int scrollTo = target.SelectedIndex;
if (IsInsert == true && target.SelectedIndex >= 0)
{
trgItems.InsertItemsAx(target.SelectedIndex, addList);
}
else
{
scrollTo = trgItems.AddItemsAx(addList);
}
target.UnselectAll();
TargetBoxItemsRefresh(target, trgItemsSource);
target.SelectedItemsAdd(addList);
if (target.SelectedIndex >= 0) target.ScrollIntoViewIndex(scrollTo);
}
catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
return true;
}