listbox

How to add item to the beginning of the list in ListBox?

匆匆过客 提交于 2019-12-03 05:35:58
Is there a way to add item to a WinForms ListBox, to the beginning of the list without rewriting entire list in a loop? Other way to solve my problem would be to display ListBox in reverse order (last item on the top) but I don't know how to do it. My ListBox control is used as a log viewer where the most recent entry should be on the top. Use the Insert method on the items of your ListBox . Razzie If I understand correctly, can't you use the Insert(int index, object item) method? For example: myListBox.Items.Insert(0, "First"); This inserts "First" as the first item of the listbox. One option

WPF ListBox that lays out its items horizontally

烈酒焚心 提交于 2019-12-03 05:28:30
问题 I'm trying to write a WPF application for displaying images from a selection. I want to display all of the available images in a banner along the top of the window, and display the main selected image in the main window for further processing. If I wanted the list on the Left of the window, displaying the images vertically, I can do this quite elegantly using databinding. <ListBox Name="m_listBox" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" > <ListBox.ItemTemplate>

How to Implement a ListBox of Checkboxes in WPF?

自古美人都是妖i 提交于 2019-12-03 04:46:06
Although somewhat experienced with writing Winforms applications, the... "vagueness" of WPF still eludes me in terms of best practices and design patterns. Despite populating my list at runtime, my listbox appears empty. I have followed the simple instructions from this helpful article to no avail. I suspect that I'm missing some sort of DataBind() method where I tell the listbox that I'm done modifying the underlying list. In my MainWindow.xaml, I have: <ListBox ItemsSource="{Binding TopicList}" Height="177" HorizontalAlignment="Left" Margin="15,173,0,0" Name="listTopics" VerticalAlignment=

ListBox+WrapPanel arrow key navigation

柔情痞子 提交于 2019-12-03 03:42:54
I'm trying to achieve the equivalent of a WinForms ListView with its View property set to View.List . Visually, the following works fine. The file names in my Listbox go from top to bottom, and then wrap to a new column. Here's the basic XAML I'm working with: <ListBox Name="thelist" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" Orientation="Vertical" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> However, default arrow key navigation does not

How to use Canvas as the ItemsPanel for an ItemsControl in Silverlight 3

Deadly 提交于 2019-12-03 02:40:16
I am trying to set the Canvas properties in an ItemsControl DataTemplate with Silverlight 3. According to this post , the only way of doing that is to set it using the ItemsContainerStyle for the ContentPresenter type, since the Canvas properties only take effect on direct children of the Canvas. This doesn't seem to work in SL3, since the ItemsControl doesn't have an ItemsContainerStyle property, so I tried a ListBox as advised by this article , but it still doesn't work. From the XAML below, I would expect to see a green square, with the numbers 10, 30, 50, 70 cascading from "NW" to "SE"

WPF - Very basic ListBox.ItemTemplate Question

。_饼干妹妹 提交于 2019-12-03 02:05:48
Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I'm learning about DataTemplating and am trying to apply a very VERY simple ItemTemplate to a ListBox. However, when I run my app, the template is completely ignored and I just get the standard-looking listbox, whereas in fact I'd expect to see a list of checkboxes with 'Test' along side. I've tried this several times and always the same result. I've checked several resource on Google and all have the same kind of syntax for defining and ItemTemplate on a ListBox, so I really cannot see where I'm going wrong. Code...

wpf border control to span the width of listboxItem

烈酒焚心 提交于 2019-12-03 01:45:22
Im trying to define a dataTemplate for a business object in my wpf application a collection of which is being bound to a ListBox. <UserControl.Resources> <DataTemplate x:Key="ResizedItemsDataTemplate" DataType="{x:Type resizer:ResizeMonitorItem}"> <Border x:Name="bdr" BorderBrush="Blue" BorderThickness="1" CornerRadius="2" Width="auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid Margin="2"> <Grid.RowDefinitions> <RowDefinition Height="14"></RowDefinition> <RowDefinition Height="14"></RowDefinition> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding

WPF/C# Binding custom object list data to a ListBox?

偶尔善良 提交于 2019-12-03 01:24:10
I've ran into a bit of a wall with being able to bind data of my custom object list to a ListBox in WPF. This is the custom object: public class FileItem { public string Name { get; set; } public string Path { get; set; } } And this is the list: private List<FileItem> folder = new List<FileItem>(); public List<FileItem> Folder { get { return folder; } } The list gets populated and maintained by a FileSystemWatcher as files get moved around, deleted, renamed, etc. All the list does is keeps tracks of names and paths. Here's what I have in the MainWindow code-behind file (it's hard coded for

How can I add a context menu to a ListBoxItem?

和自甴很熟 提交于 2019-12-03 01:10:28
I have a ListBox and I want to add a context menu to each item in the list. I've seen the "solution" to have the right click select an item and suppress the context menu if on white space, but this solution feels dirty. Does anyone know a better way? This way the menu will pop up next to the mouse private string _selectedMenuItem; private readonly ContextMenuStrip collectionRoundMenuStrip; public Form1() { var toolStripMenuItem1 = new ToolStripMenuItem {Text = "Copy CR Name"}; toolStripMenuItem1.Click += toolStripMenuItem1_Click; var toolStripMenuItem2 = new ToolStripMenuItem {Text = "Get

Propagate ListBoxItem IsSelected trigger to child control

旧城冷巷雨未停 提交于 2019-12-03 00:14:43
问题 I'm developing a CheckedListBox with self removable ListBoxItem s. The problem is that an item only gets checked if the user clicks on the CheckBox area, which is kind of awkward. How do I create ListBoxItem triggers ( IsSelected ) to check the checkboxes on a "DataSourced" ListBox ? Eg: Below is my control (all other code have been omitted for brevity): <ListBox x:Name="executors" ItemsSource="{Binding Executors}" HorizontalAlignment="Left" Height="121" Margin="23,19,0,0" VerticalAlignment=