本文整理汇总了C#中System.Windows.Controls.ListBox.ScrollIntoView方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ScrollIntoView方法的具体用法?C# ListBox.ScrollIntoView怎么用?C# ListBox.ScrollIntoView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ListBox
的用法示例。
在下文中一共展示了ListBox.ScrollIntoView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: show
public void show(MainWindow con, ListBox lb, string kto, string text, int tem)
{
if (!lb.CheckAccess())
{
con.Dispatcher.Invoke(DispatcherPriority.Send,
(Action)delegate
{
UserWiad itm = new UserWiad();
itm.Nick = kto;
itm.Wiad = text;
itm.Typ = tem;
lb.Items.Add(itm);
lb.ScrollIntoView(itm);
});
}
else
{
UserWiad itm = new UserWiad();
itm.Nick = kto;
itm.Wiad = text;
itm.Typ = tem;
lb.Items.Add(itm);
lb.ScrollIntoView(itm);
}
}
示例2: OnAutoScrollToCurrentItem
/// <summary>
/// This method will be called when the ListBox should
/// be scrolled to the given index
/// </summary>
/// <param name="listBox">The ListBox which should be scrolled</param>
/// <param name="index">The index of the item to which it should be scrolled</param>
public static void OnAutoScrollToCurrentItem(ListBox listBox, int index)
{
if (listBox != null && listBox.Items != null && listBox.Items.Count > index && index >= 0)
{
listBox.ScrollIntoView(listBox.Items[index]);
}
}
示例3: AddNewFileType
private void AddNewFileType(ListBox control) {
ICollection<FileTypeEntry> source = (ICollection<FileTypeEntry>)control.ItemsSource;
FileTypeEntry item = new FileTypeEntry(this, "");
source.Add(item);
control.SelectedItem = item;
control.ScrollIntoView(item);
control.Focus();
item.IsEditing = true;
}
示例4: ListBoxRemoveSelected
private bool ListBoxRemoveSelected(ListBox list)
{
if (list.Items.Count > 0 && list.SelectedIndex >= 0)
{
int selected = list.SelectedIndex;
list.Items.RemoveAt(selected);
if (list.Items.Count > selected)
list.SelectedIndex = selected;
else
list.SelectedIndex = (list.Items.Count - 1);
if (list.SelectedIndex > -1)
list.ScrollIntoView(list.Items[list.SelectedIndex]);
return true;
}
return false;
}
示例5: UpdateLayout
public static void UpdateLayout(ListBox item, bool isfirst)
{
try
{
item.UpdateLayout();
if (isfirst)
item.ScrollIntoView(item.Items.First());
else
item.ScrollIntoView(item.Items.Last());
item.UpdateLayout();
}
catch (Exception ex)
{
//BugSenseHandler.Instance.SendExceptionAsync(ex);
//MessageBox.Show(ex.Message);
}
}
示例6: ListBoxMoveSelectedDown
private bool ListBoxMoveSelectedDown(ListBox list)
{
if (list.Items.Count > 0 && list.SelectedIndex < (list.Items.Count - 1))
{
int selected_index = list.SelectedIndex;
var saved = list.Items[selected_index];
list.Items[selected_index] = list.Items[selected_index + 1];
list.Items[selected_index + 1] = saved;
list.SelectedIndex = selected_index + 1;
list.ScrollIntoView(list.Items[selected_index + 1]);
return true;
}
return false;
}
示例7: MoveListPosition
void MoveListPosition(ListBox listBox, int distance)
{
int i = listBox.Items.CurrentPosition + distance;
if (i >= 0 && i < listBox.Items.Count)
{
listBox.Items.MoveCurrentToPosition(i);
listBox.SelectedIndex = i;
listBox.ScrollIntoView(listBox.Items[i]);
}
}
示例8: OnAutoScrollToNewItem
/// <summary>
/// This method will be called when the ListBox should
/// be scrolled to the end
/// </summary>
/// <param name="listBox">The ListBox which should be scrolled</param>
public static void OnAutoScrollToNewItem( ListBox listBox )
{
if( listBox != null && listBox.Items != null && listBox.Items.Count > 0 && listBox.SelectedItem == listBox.Items[0] )
listBox.ScrollIntoView( listBox.Items[listBox.Items.Count - 1] );
}
示例9: ShowListBox
void ShowListBox(object sender, int count)
{
//int line = 0;
//try {
if (listBox == null)
{
listBox = new ListBox();
if (count >= 5) { ScrollViewer.SetVerticalScrollBarVisibility(listBox, ScrollBarVisibility.Visible); }
listBox.SelectionChanged += (s, e) =>
{
if (listBox.SelectedItem != null && listBox.Items.Contains(listBox.SelectedItem))
{
try
{
listBox.ScrollIntoView(listBox.SelectedItem);
}
catch { }
}
};
listBox.MinWidth = textBox.RenderSize.Width;
ArmoryLoadDialog dialog = (ArmoryLoadDialog)sender;
//var canvas = (Grid)System.Windows.Application.Current.RootVisual;
var canvas = (Grid)dialog.LayoutRoot;
var transform = textBox.TransformToVisual(canvas);
var topLeft = transform.Transform(new Point(0, 0));
Canvas.SetLeft(listBox, topLeft.X);
Canvas.SetTop(listBox, topLeft.Y + textBox.RenderSize.Height);
canvas.Children.Add(listBox);
}
if (count >= 5)
{
count = 5;
}
listBox.MaxHeight = count * 21;
//} catch (Exception ex) {
//new Rawr.DPSWarr.ErrorBoxDPSWarr("AutoComplete issue", ex.Message, "ShowListBox", "No Additional Info", ex.StackTrace, line);
//}
}
示例10: SelectListItem
// Update list based on selection.
// Return true if there's an exact match, or false if not.
static bool SelectListItem(ListBox list, object value)
{
ItemCollection itemList = list.Items;
// Perform a binary search for the item.
int first = 0;
int limit = itemList.Count;
while (first < limit)
{
int i = first + (limit - first) / 2;
var item = (IComparable)(itemList[i]);
int comparison = item.CompareTo(value);
if (comparison < 0)
{
// Value must be after i
first = i + 1;
}
else if (comparison > 0)
{
// Value must be before i
limit = i;
}
else
{
// Exact match; select the item.
list.SelectedIndex = i;
itemList.MoveCurrentToPosition(i);
list.ScrollIntoView(itemList[i]);
return true;
}
}
// Not an exact match; move current position to the nearest item but don't select it.
if (itemList.Count > 0)
{
int i = Math.Min(first, itemList.Count - 1);
itemList.MoveCurrentToPosition(i);
list.ScrollIntoView(itemList[i]);
}
return false;
}
示例11: RefreshListAsync
private static void RefreshListAsync(TextBox textBox, ListBox listBox, string word, PrefixDictionary<KeyValuePair<string, object>[]> dict, Action callback, StringComparison comparison)
{
var matches = dict.Search(word, false).Select(found => found.Value).SelectMany(found => found).ToList();
listBox.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate{
var ev = (QueryCandidatesEventHandler)textBox.GetValue(QueryCandidatesProperty);
if(ev != null){
var e = new QueryCandidatesEventArgs(word);
foreach(var del in ev.GetInvocationList()){
del.DynamicInvoke(new object[]{textBox, e});
if(e.Candidates != null){
matches.AddRange(e.Candidates);
}
}
}
}));
listBox.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate{
bool isIns = GetIsInsertAutomatically(textBox);
listBox.ItemsSource = null;
listBox.ItemsSource = matches.ToArray();
SetState(listBox, new AutoCompleteState(){TextBox = textBox});
listBox.SelectionChanged -= ListBox_SelectionChanged;
if(isIns){
listBox.SelectionChanged += ListBox_SelectionChanged;
}
if(listBox.Items.Count > 0){
listBox.SelectedIndex = 0;
listBox.ScrollIntoView(listBox.SelectedItem);
}
if(!isIns){
listBox.SelectionChanged += ListBox_SelectionChanged;
}
if(callback != null){
callback();
}
}));
}
示例12: Select
bool Select(ListBox list, object item)
{
try
{
if (item == null)
return false;
list.SelectedItem = item;
list.ScrollIntoView(item);
return true;
}
catch
{
return false;
}
}
示例13: Initialize
public void Initialize()
{
try
{
double aspectRatio = Math.Round((double)ClientGameEngine.Get().ClientDimensions.Width / (double)ClientGameEngine.Get().ClientDimensions.Height, 2, MidpointRounding.AwayFromZero);
string UIComponentPath = "resources\\UI\\PreGameLobby\\";
string ratioPath = string.Empty;
if (aspectRatio == 1.33)
ratioPath = "4x3\\";
else
ratioPath = "16x9\\";
//background
BitmapImage bitmapImage = new BitmapImage();
bitmapImage = new BitmapImage(new Uri(UIComponentPath + ratioPath + "Background.png", UriKind.RelativeOrAbsolute));
m_BackgroundBrush = new ImageBrush(bitmapImage);
ClientGameEngine.Get().AllPlayersReady.ValueChanged += (from, to) =>
{
if (to)
{
Action action = () =>
{
m_StartEnabledImage.Visibility = Visibility.Visible;
m_StartEnabledImage.IsEnabled = true;
m_StartDisabledImage.Visibility = Visibility.Hidden;
};
ClientGameEngine.Get().ExecuteOnUIThread(action);
}
else
{
Action action = () =>
{
m_StartDisabledImage.Visibility = Visibility.Visible;
m_StartEnabledImage.IsEnabled = false;
m_StartEnabledImage.Visibility = Visibility.Hidden;
};
ClientGameEngine.Get().ExecuteOnUIThread(action);
}
};
//Chat Text Box
m_ChatMessageBox = new TextBox();
m_ChatMessageBox.Opacity = 0.75;
m_ChatMessageBox.FontFamily = new FontFamily("Papyrus");
m_ChatMessageBox.FontSize = 18;
m_ChatMessageBox.KeyDown += (s, ev) =>
{
if (ev.Key == Key.Enter)
{
if (m_ChatMessageBox.Text.Trim() != string.Empty)
{
GameChatMessage chat = new GameChatMessage() { Contents = m_ChatMessageBox.Text.Trim() };
m_ChatMessageBox.Text = "";
ClientGameEngine.Get().SendMessageToServer(chat);
}
}
};
//Chat Message OK
m_SendButton = new Button();
m_SendButton.FontFamily = new FontFamily("Papyrus");
m_SendButton.FontSize = 18;
m_SendButton.Content = "Send";
m_SendButton.Click += (s, ev) =>
{
if (m_ChatMessageBox.Text.Trim() != string.Empty)
{
GameChatMessage chat = new GameChatMessage() { Contents = m_ChatMessageBox.Text.Trim() };
m_ChatMessageBox.Text = "";
ClientGameEngine.Get().SendMessageToServer(chat);
}
};
//Chat messages
m_ChatMessagesListBox = new ListBox();
m_ChatMessagesListBox.ItemsSource = ClientGameEngine.Get().ChatMessageCollection;
m_ChatMessagesListBox.Opacity = 0.75;
m_ChatMessagesListBox.FontFamily = new FontFamily("Papyrus");
m_ChatMessagesListBox.FontSize = 14;
ClientGameEngine.Get().ChatMessageCollection.CollectionChanged += (s, ev) =>
{
if (ev.NewItems != null)
{
m_ChatMessagesListBox.ScrollIntoView(ev.NewItems[0]);
}
};
//StartEnabled
bitmapImage = new BitmapImage(new Uri(UIComponentPath + "Start.png", UriKind.RelativeOrAbsolute));
m_StartEnabledImage = new Image();
m_StartEnabledImage.Source = bitmapImage;
m_StartEnabledImage.Width = bitmapImage.PixelWidth;
m_StartEnabledImage.Height = bitmapImage.PixelHeight;
m_StartEnabledImage.Visibility = Visibility.Hidden;
m_StartEnabledImage.IsEnabled = false;
m_StartEnabledImage.Name = "StartEnabled";
m_StartEnabledImage.MouseEnter += MenuOptionHover;
//.........这里部分代码省略.........
示例14: ScrollListBoxItemIntoView
static void ScrollListBoxItemIntoView(ListBox listBox, object item)
{
listBox.ScrollIntoView(item);
}
示例15: Initialize
public void Initialize()
{
InGameEngine.InGameEngine.Get();
//Chat Text Box
m_ChatMessageBox = new TextBox();
m_ChatMessageBox.Opacity = 0.75;
m_ChatMessageBox.FontFamily = new FontFamily("Papyrus");
m_ChatMessageBox.FontSize = 12;
m_ChatMessageBox.KeyDown += (s, ev) =>
{
if (ev.Key == Key.Enter)
{
if (m_ChatMessageBox.Text.Trim() != string.Empty)
{
GameChatMessage chat = new GameChatMessage() { Contents = m_ChatMessageBox.Text.Trim() };
m_ChatMessageBox.Text = "";
ClientGameEngine.Get().SendMessageToServer(chat);
}
}
};
m_EndTurnButton = new Button { FontFamily = new FontFamily("Papyrus"), FontSize = 18, Content = "End Turn" };
m_EndTurnButton.Click += (s, ev) =>
{
if (InGameEngine.InGameEngine.Get().MoveList.Count > 0)
{
ClientGameEngine.Get().SendMessageToServer((new EndMoveTurnMessage() { Moves = InGameEngine.InGameEngine.Get().MoveList }));
}
};
m_UITopImage = new Image();
BitmapImage bimg = new BitmapImage(new Uri(@"resources\UI\Game\TopBar.png", UriKind.RelativeOrAbsolute));
m_UITopImage.Source = bimg;
m_UITopImage.Width = bimg.PixelWidth;
m_UITopImage.Height = bimg.PixelHeight;
m_UILeftImage = new Image();
bimg = new BitmapImage(new Uri(@"resources\UI\Game\LeftBar.png", UriKind.RelativeOrAbsolute));
m_UILeftImage.Source = bimg;
m_UILeftImage.Width = bimg.PixelWidth;
m_UILeftImage.Height = bimg.PixelHeight;
m_UIRightImage = new Image();
bimg = new BitmapImage(new Uri(@"resources\UI\Game\RightBar.png", UriKind.RelativeOrAbsolute));
m_UIRightImage.Source = bimg;
m_UIRightImage.Width = bimg.PixelWidth;
m_UIRightImage.Height = bimg.PixelHeight;
m_UIBottomImage = new Image();
bimg = new BitmapImage(new Uri(@"resources\UI\Game\BottomBar.png", UriKind.RelativeOrAbsolute));
m_UIBottomImage.Source = bimg;
m_UIBottomImage.Width = bimg.PixelWidth;
m_UIBottomImage.Height = bimg.PixelHeight;
//Menu Button
m_MenuButton = new Button();
m_MenuButton.FontFamily = new FontFamily("Papyrus");
m_MenuButton.FontSize = 18;
m_MenuButton.Content = "Menu";
m_MenuButton.Click += (s, ev) =>
{
};
//Chat messages
m_ChatMessagesListBox = new ListBox();
m_ChatMessagesListBox.ItemsSource = ClientGameEngine.Get().ChatMessageCollection;
m_ChatMessagesListBox.Opacity = 0.75;
m_ChatMessagesListBox.FontFamily = new FontFamily("Papyrus");
m_ChatMessagesListBox.FontSize = 12;
ClientGameEngine.Get().ChatMessageCollection.CollectionChanged += (s, ev) =>
{
if (ev.NewItems != null)
{
m_ChatMessagesListBox.ScrollIntoView(ev.NewItems[0]);
}
};
//unit stats
m_UnitStatsGroupBox = new GroupBox();
m_UnitStatsGroupBox.Opacity = 0.75;
m_UnitStatsGroupBox.FontFamily = new FontFamily("Papyrus");
m_UnitStatsGroupBox.FontSize = 12;
}