本文整理汇总了C#中System.Windows.Controls.ListBox.ScrollIntoViewFix方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ScrollIntoViewFix方法的具体用法?C# ListBox.ScrollIntoViewFix怎么用?C# ListBox.ScrollIntoViewFix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBox
的用法示例。
在下文中一共展示了ListBox.ScrollIntoViewFix方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addItems
public void addItems(ListBox src, ListBox target, bool IsInsert = false)
{
try
{
if (src == null || target == null) return;
int LastIndex = -1;
foreach (object info in src.SelectedItems)
{
if (IsEnableAdd(target, info) == true)
{
if (IsInsert == true && target.SelectedItem != null)
{
target.Items.Insert(target.SelectedIndex + 1, info);
target.SelectedIndex += 1;
LastIndex = target.SelectedIndex;
}
else
{
target.Items.Add(info);
LastIndex = target.Items.Count - 1;
}
}
}
if (target.Items.Count != 0 && LastIndex >=0)
{
target.SelectedIndex = LastIndex;
target.ScrollIntoViewFix(LastIndex);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
}
}
示例2: move_item
/// <summary>アイテムを移動</summary>
public void move_item(ListBox target, int direction)
{
try
{
if (target == null || target.SelectedItem == null) return;
object temp = target.SelectedItem;
int newIndex = ((target.SelectedIndex + direction) % target.Items.Count + target.Items.Count) % target.Items.Count;
target.Items.RemoveAt(target.SelectedIndex);
target.Items.Insert(newIndex, temp);
target.SelectedIndex = newIndex;
target.ScrollIntoViewFix(newIndex);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
}
}
示例3: getBoxKeyEnableHandler
private KeyEventHandler getBoxKeyEnableHandler(ListBox box, KeyEventHandler handler, bool src)
{
return new KeyEventHandler((sender, e) =>
{
if (Keyboard.Modifiers == ModifierKeys.None)
{
switch (e.Key)
{
case Key.Escape:
if (box.SelectedItem != null)
{
box.UnselectAll();
e.Handled = true;
}
break;
case Key.Enter:
if (src == true)
{
handler(sender, e);
//一つ下へ移動する。ただし、カーソル位置は正しく動かない。
int pos = box.SelectedIndex + 1;
box.SelectedIndex = Math.Max(0, Math.Min(pos, box.Items.Count - 1));
box.ScrollIntoViewFix(box.SelectedIndex);
e.Handled = true;
}
break;
case Key.Delete:
if (src == false)
{
handler(sender, e);
e.Handled = true;
}
break;
}
}
});
}
示例4: deleteItems
public void deleteItems(ListBox target)
{
try
{
if (target == null) return;
int newSelectedIndex = -1;
while (target.SelectedIndex >= 0)
{
newSelectedIndex = target.SelectedIndex;
target.Items.RemoveAt(newSelectedIndex);
}
if (target.Items.Count != 0)
{
target.Items.Refresh();
newSelectedIndex = (newSelectedIndex == target.Items.Count ? newSelectedIndex - 1 : newSelectedIndex);
target.SelectedIndex = newSelectedIndex;
target.ScrollIntoViewFix(newSelectedIndex);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
}
}