本文整理汇总了C#中System.Windows.Controls.ListBox类的典型用法代码示例。如果您正苦于以下问题:C# ListBox类的具体用法?C# ListBox怎么用?C# ListBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListBox类属于System.Windows.Controls命名空间,在下文中一共展示了ListBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoScrollHandler
public AutoScrollHandler(System.Windows.Controls.ListBox target)
{
Target = target;
Binding B = new Binding("ItemsSource");
B.Source = Target;
BindingOperations.SetBinding(this, ItemsSourceProperty, B);
}
示例2: GetContent
protected override FrameworkElement GetContent()
{
int totalHeight = 0;
ListBox removeOptions = new ListBox();
for(int i = 0 ; i < _tree.Items.Count; i ++)
if (_tree.Items[i] is PatternBase)
{
totalHeight += 25; //default height of an item
TextBlock pattern = new TextBlock()
{
Text = (_tree.Items[i] as PatternBase).BioPatternName,
Name = i.ToString(), //store the id as name so we can remove it later...
Width = 150
};
pattern.MouseLeftButtonUp += new MouseButtonEventHandler(RemoveSelectedPattern);
removeOptions.Items.Add(pattern);
}
Grid grid = new Grid()
{
Height = totalHeight,
Width = 170
};
grid.Children.Add(removeOptions);
return grid;
}
示例3: fillList
private void fillList(ListBox listPlaylist)
{
if (!Directory.Exists(PathPlaylist))
Directory.CreateDirectory(PathPlaylist);
try
{
string[] listFiles = Directory.GetFiles(PathPlaylist, "*.pls");
foreach (string fileName in listFiles)
{
try
{
Playlist onePlaylist = new Playlist(fileName);
onePlaylist.ParsePlaylist();
listPlaylist.Items.Add(onePlaylist);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例4: AddSelectionEvent
static void AddSelectionEvent(ListBox list)
{
list.SelectionChanged += delegate
{
MessageBox.Show("");
};
}
示例5: GetInformationToSave
private static string GetInformationToSave(int cas, MainWindow mw)
{
ListBox listBox = new ListBox();
switch (cas)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
listBox = mw.listBoxError_Test;
break;
}
string contents = "";
foreach (string ligne in listBox.Items)
{
contents += ligne + "\r\n";
}
return contents;
}
示例6: switch
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
this.remoteClientList = ((System.Windows.Controls.ListBox)(target));
return;
case 2:
#line 18 "..\..\AddAppDialog.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.OKButton_Clicked);
#line default
#line hidden
return;
case 3:
#line 20 "..\..\AddAppDialog.xaml"
((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.CancelButton_Clicked);
#line default
#line hidden
return;
}
this._contentLoaded = true;
}
示例7: OnApplyTemplate
public override void OnApplyTemplate()
{
if (ResultsListBox != null)
ResultsListBox.SelectionChanged -= ResultListBox_SelectionChanged;
if (MapDetailsControl != null)
{
MapDetailsControl.MapDetailsChanged -= RaiseMapDetailsChanged;
MapDetailsControl.MapSelectedForOpening -= RaiseMapSelectedForOpening;
}
base.OnApplyTemplate();
MapDetailsControl = GetTemplateChild("MapDetailsControl") as MapDetailsControl;
ResultsListBox = GetTemplateChild("ResultsListBox") as ListBox;
if (ResultsListBox != null)
{
ResultsListBox.SelectionChanged += ResultListBox_SelectionChanged;
ResultsListBox.Tag = this;
}
if (MapDetailsControl != null)
{
MapDetailsControl.MapDetailsChanged += RaiseMapDetailsChanged;
MapDetailsControl.MapSelectedForOpening += RaiseMapSelectedForOpening;
}
}
示例8: ListColorNames
public ListColorNames()
{
Title = "List Color Names";
ListBox lstbox = new ListBox();
lstbox.Width = 150; // ��
lstbox.Height = 150; //����
lstbox.SelectionChanged += ListBoxOnSelectionChanged; // �̺�Ʈ ���
Content = lstbox; //win�� ���(ȭ�鿡 ���)
//1��
/*
//��������� ListBox�� ü���
PropertyInfo[] props = typeof(Colors).GetProperties();
//GetProperties �� Colors�� �ִ� ������Ƽ 141���� �迭�� �����´�.
//������ PropertyInfo Ÿ���� �迭�� �ϳ��� ������ Name���� �̸��� ����Ʈ �ڽ��� �߰��Ѵ�.
foreach (PropertyInfo prop in props)
lstbox.Items.Add(prop.Name);
*/
//2��
PropertyInfo[] props = typeof(Colors).GetProperties();
//����Ʈ �ڽ��� Color ������ ü���...
foreach (PropertyInfo prop in props)
lstbox.Items.Add(prop.GetValue(null, null));
}
示例9: CreateAndInitListBox
private ListBox CreateAndInitListBox()
{
ListBox lst = new ListBox();
lst.Margin = new Thickness(10, 10, 10, 10);
return lst;
}
示例10: worker_RunWorkerCompleted
void worker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var winFabSortedList = winFabInterest;
ListBox lstBx = new ListBox();
lstBx.Height = this.MainPanel.Height;
lstBx.Width = this.MainPanel.Width;
this.MainPanel.Children.Add(lstBx);
if (winFabSortedList.Count == 0)
{
MessageBox.Show("No Records Found.Try changing the folder option.");
}
else
{
foreach (var itm in winFabSortedList)
{
EmailDataModel emailObj = new EmailDataModel();
emailObj.SenderName = itm.SenderName;
emailObj.SenderGroup = itm.SenderGroup;
emailObj.SenderParticipation = itm.SenderParticipation;
emailObj.SenderContact = itm.SenderContact;
InterestControl intControl = new InterestControl();
intControl.SetUI(emailObj);
lstBx.Items.Add(intControl);
}
}
this.EllipseAnimate.Visibility = Visibility.Collapsed;
this.EllipseAnimate.Visibility = Visibility.Collapsed;
this.UpdateLayout();
}
示例11: IsFirstItemVisible
public static bool IsFirstItemVisible(ListBox listbox)
{
if (listbox.Items.Count == 0)
return false;
var listboxRectangle = new Rect(new Point(0, 0), listbox.RenderSize);
double visiblePercent = 0;
ListBoxItem item = listbox.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem;
if (item != null)
{
var itemTransform = item.TransformToVisual(listbox);
var itemRectangle = itemTransform.TransformBounds(new Rect(new Point(0, 0), item.RenderSize));
itemRectangle.Intersect(listboxRectangle);
if (!itemRectangle.IsEmpty)
{
visiblePercent = itemRectangle.Height / item.RenderSize.Height * 100;
}
}
if (visiblePercent > 0)
return true;
else
return false;
}
示例12: AddItemToList
public void AddItemToList(RecognitionResult speech, ListBox list, Color color)
{
ListBoxItem item = CreateDefaultListBoxItem();
item.Content = "S:" + speech.Text + " C:" + speech.Confidence;
item.Foreground = new SolidColorBrush(color);
AddToList(list, item);
}
示例13: ListColorsEvenElegantlier
public ListColorsEvenElegantlier()
{
Title = "List Colors Even Elegantlier";
DataTemplate template = new DataTemplate(typeof(NamedBrush));
FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel));
factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
template.VisualTree = factoryStack;
FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle));
factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0);
factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0);
factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2));
factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush);
factoryRectangle.SetBinding(Rectangle.FillProperty, new Binding("Brush"));
factoryStack.AppendChild(factoryRectangle);
FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));
factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name"));
factoryStack.AppendChild(factoryTextBlock);
ListBox lstbox = new ListBox();
lstbox.Width = 150;
lstbox.Height = 150;
Content = lstbox;
lstbox.ItemTemplate = template;
lstbox.ItemsSource = NamedBrush.All;
lstbox.SelectedValuePath = "Brush";
lstbox.SetBinding(ListBox.SelectedValueProperty, "Background");
lstbox.DataContext = this;
}
示例14: switch
void IComponentConnector.Connect(int connectionId, object target)
{
switch (connectionId)
{
case 1:
this.syncMovies = (CheckBox) target;
return;
case 2:
this.syncMoviesAll = (CheckBox) target;
return;
case 3:
this.moviesListBox = (ListBox) target;
this.moviesListBox.PreviewKeyDown += new KeyEventHandler(this.listBox_PreviewKeyDown);
return;
case 4:
this.drmMessage = (TextBlock) target;
return;
case 5:
this.cancelButton = (Button) target;
return;
case 6:
this.syncButton = (Button) target;
return;
}
this._contentLoaded = true;
}
示例15: 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);
}
}