listbox

Selection bug for listbox where the list items are value types / structs and contain duplicates?

瘦欲@ 提交于 2019-11-29 11:23:08
I turned an Horizontal ItemsControl to a Listbox so that I am able to select individual items but found that the selection was broken. Took some time to distill out the problematic bit. Books = new[] { new Book{Id=1, Name="Book1"}, new Book{Id=2, Name="Book2"}, new Book{Id=3, Name="Book3"}, new Book{Id=4, Name="Book4"}, new Book{Id=3, Name="Book3"}, }; <DataTemplate DataType="{x:Type WPF_Sandbox:Book}"> <TextBlock Text="{Binding Name}"/> </DataTemplate> <ListBox ItemsSource="{Binding Books}"/> If Book is a struct, the listbox selection (default mode : single) goes awry if you select an item

Gaps between items in my ListBox

旧街凉风 提交于 2019-11-29 10:50:17
问题 When I create ListBox with horizontal items ordering for example like this: <DockPanel> <ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBoxItem> <Button Content="Hello" /> </ListBoxItem> <ListBoxItem> <Button Content="Hello" /> </ListBoxItem> </ListBox> </DockPanel> I have small gaps between buttons in the list as indicated by the arrows on following picture: How can I get rid of those

WPF Filter a ListBox

浪尽此生 提交于 2019-11-29 09:29:57
I load a list of strings in my ListBox , now I want to filter it when I enter text in a TextBox . How can I do it? public void ListLoad() { ElementList = new List<string>(); // creation a list of strings ElementList.Add("1"); // add a item of string ElementList.Add("2"); // add a item of string DataContext = this; // set the data context } I'm binding it in XAML with: ItemsSource="{Binding ElementList}" CollectionViewSource class can help here. As far as I can tell it has many capabilities to filter, sort and group collections. ICollectionView view = CollectionViewSource.GetDefaultView

How to list text files in the selected directory in a listbox?

╄→гoц情女王★ 提交于 2019-11-29 09:22:42
How can I list the text files in a certain directory (C:\Users\Ece\Documents\Testings) in a listbox of a WinForm(Windows application)? // What directory are the files in?... DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestDirectory"); // What type of file do we want?... FileInfo[] Files = dinfo.GetFiles("*.txt"); // Iterate through each file, displaying only the name inside the listbox... foreach( FileInfo file in Files ) { listbox1.Items.Add(file.Name); } // A statement, followed by a smiley face... That oughta do it. ;o) To get the txt files, try this: string folder = @"C:\Users\Ece

WPF ListBox Selection Color

不打扰是莪最后的温柔 提交于 2019-11-29 09:19:19
Sorry if this has been asked before, but I couldn't find a solution to what I'm looking for in the related questions that popped up, or on Google. In my application I'm trying to recreate Words New Document dialog, list on the left of items and on the right an icon with text underneath. In Word it has the orange gradient when you mouse over, and a darker gradient when you select an item. I've got most of this recreated, except for changing the background color once you select an item. Here's the code I'm using to create this: <ListView Margin="236,34,17,144" Name="listView1"

Automatic Scrolling in a Silverlight List Box

China☆狼群 提交于 2019-11-29 09:18:43
How can I programmatically force a silverlight list box to scroll to the bottom so that the last item added is always visible. I've tried simply selecting the item. It ends up as selected but still not visible unless you manually scroll to it. Use the ListBox's ScrollIntoView method passing in the last item. You may need to call UpdateLayout immediately before it for it to work. The ScrollIntoView() method will scroll the last item into view, however listBox.UpdateLayout() must be called just before ScrollIntoView(). Here is a complete method with code: // note that I am programming

Xamly determine if a ListBox.Items.Count > 0

ぐ巨炮叔叔 提交于 2019-11-29 09:03:45
Is there a way in XAML to determine if the ListBox has data? I wanna set its IsVisibile property to false if no data. Bryan Anderson The ListBox contains a HasItems property you can bind to. So you can just do this: <BooleanToVisibilityConverter x:Key="BooleanToVisibility" /> ... <ListBox Visibility="{Binding HasItems, RelativeSource={RelativeSource Self}, Converter=BooleanToVisibility}" /> Or as a Trigger so you don't need the converter: <ListBox> <ListBox.Style> <Style TargetType="{x:Type ListBox}"> <Setter Property="Visibility" Value="Visible" /> <Style.Triggers> <DataTrigger Binding="

.NET 3.5 Listbox Selected Values (Winforms)

你说的曾经没有我的故事 提交于 2019-11-29 08:45:33
I am BATTLING to get the selected values (please note VALUES not TEXT) from a Winforms Listbox that has multi-select enabled and has been bound to a database table getting the Name (as DisplayMember) and ID (as ValueMember) - I need the ID of the selected items. The listbox control has properties for SelectedValue to get one of the selected items values, but not for all selected items values. The SelectedItems property returns a Listbox.SelectedObjectCollection from which I cannot seem to extract the VALUES of the items. Please help! Thanks. Try casting each object in the collection to the

changing order of items in tkinter listbox

眉间皱痕 提交于 2019-11-29 08:40:26
Is there an easier way to change the order of items in a tkinter listbox than deleting the values for specific key, then re-entering new info? For example, I want to be able to re-arrange items in a listbox. If I want to swap the position of two, this is what I've done. It works, but I just want to see if there's a quicker way to do this. def moveup(self,selection): value1 = int(selection[0]) - 1 #value to be moved down one position value2 = selection #value to be moved up one position nameAbove = self.fileListSorted.get(value1) #name to be moved down nameBelow = self.fileListSorted.get(value2

Changing WPF Listbox SelectedItem text color and highlight/background Color using C#

孤者浪人 提交于 2019-11-29 07:33:41
I am trying to change the highlighted(selected) color and the highlighted text color of a wpf listbox at runtime. I have tried creating a style and applying it as follows: Style s = new Style(typeof(ListBox)); s.Resources.Add(SystemColors.HighlightBrushKey, Setting.ListSelectedColor); s.Resources.Add(SystemColors.HighlightTextBrushKey, Setting.ListSelectedTextColor); lstGames.Style = s; But this seems to do nothing. Is there any way to achieve this? EDIT: Per suggestions, I tried using DynamicResources to achieve this, but so far this has not been successful either. My code for this: