listbox

WPF Listbox and Select All

坚强是说给别人听的谎言 提交于 2019-11-30 12:37:49
I want to create a simple ListBox and have SelectAll as a context menu item. However it seems that ListBox has some sort of inbuilt handling for SelectAll that I can't get working, but is interfering with my attempt to implement SelectAll. My entire XAML is this: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.SelectAll" Executed="SelectAllExecuted" /> </Window

Stretch ListBox Items hit area to full width of the ListBox? ListBox style is set implicity through a theme

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 11:46:02
I've looked around for an answer on this, but the potential duplicates are more concerned with presentation than interaction. I have a basic list box, and each item's content is a simple string. The ListBox itself is stretched to fill it's grid container, but each ListBoxItem's hitarea does not mirror the ListBox width. It looks as if the hitarea (pointer contact area) for each item is only the width of the text content. How do I make this stretch all the way across, regardless of the text size. I've set HorizontalContentAlignment to Stretch, but this doesn't solve my problem. My only other

Right Click to select items in a ListBox

回眸只為那壹抹淺笑 提交于 2019-11-30 10:59:40
I'm trying to make a list of items that you can do several actions with by right-clicking and having a context menu come up. I've completed that, no problem whatsoever. But I'd like to have it so that when you right click on a item, instead of leaving the current item selected, to select the item the mouse is over. I've researched this and other related questions, and I've tried to use indexFromPoint (which I found through my research) but whenever I right click on a item, it always just clears the selected item and doesn't show the context menu, as I have it set so that it wont appear if

WPF Drag & drop from ListBox with SelectionMode Multiple

我的梦境 提交于 2019-11-30 10:59:38
I've almost got this working apart from one little annoying thing... Because the ListBox selection happens on mouse down, if you start the drag with the mouse down when selecting the last item to drag it works fine, but if you select all the items to drag first and then click on the selection to start dragging it, the one you click on gets unselected and left behind after the drag. Any thoughts on the best way to get around this? <DockPanel LastChildFill="True"> <ListBox ItemsSource="{Binding SourceItems}" SelectionMode="Multiple" PreviewMouseLeftButtonDown="HandleLeftButtonDown"

How can I disable horizontal scrolling in a WPF ListBox?

余生长醉 提交于 2019-11-30 10:42:47
问题 This seems to be an absurdly simple question but Google and Stack Overflow searches yield nothing. How can I disable horizontal scrolling in a WPF ListBox when items take up more horizontal space than is available in the box? 回答1: In XAML: <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" /> In C#: myListBox.SetValue( ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); 来源: https://stackoverflow.com/questions/373778/how-can-i-disable-horizontal

Find control inside Listbox.ItemTemplate (WPF C#)

丶灬走出姿态 提交于 2019-11-30 09:49:36
I have some problems finding the right TextBlock control inside a StackPanel . My markup: <ListBox Name="lstTimeline" ItemContainerStyle="{StaticResource TwItemStyle}" MouseDoubleClick="lstTimeline_MouseDoubleClick"> <ListBox.ItemTemplate> <DataTemplate> <DockPanel MaxWidth="{Binding ElementName=lstTimeline, Path=ActualWidth}"> <Border Margin="10" DockPanel.Dock="Left" BorderBrush="White" BorderThickness="1" Height="48" Width="48" HorizontalAlignment="Center"> <Image Source="{Binding ThumbNail, IsAsync=True}" Height="48" Width="48" /> </Border> <StackPanel Name="stkPanel" Margin="10" DockPanel

How to get Selected items in WPF CheckBox ListBox

感情迁移 提交于 2019-11-30 09:47:39
问题 Am Using the checkbox in listbox items, how to get the selected checkboxes from the list <ListBox ItemsSource="{Binding NameList}" HorizontalAlignment="Left" Margin="16,68,0,12" Name="listBox1" Width="156" IsEnabled="True" SelectionMode="Multiple" Focusable="True" IsHitTestVisible="True" IsTextSearchEnabled="False" FontSize="12" Padding="5" SelectionChanged="listBox1_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Content="{Binding Path

Categorize Listbox items by Color

最后都变了- 提交于 2019-11-30 09:47:37
问题 So I'm trying to make a listbox with 2 buttons. Listbox is supposed to display files from a specific folder (I get back to this) And the two buttons are supposed to be called "Set.." (As in set directory) and Update (As the list will be refreshed (Something I do every time the Windows Form Runs. So as of now, when I start my application, and go to the form with the listbox, the listbox is empty. When pressing "Update", the List box picks up files from an address located on my Harddrive (So

Setting selected item in a ListBox without looping

跟風遠走 提交于 2019-11-30 09:32:01
I have a multi-select listbox which I am binding to a DataTable. DataTable contains 2 columns description and value. Here's the listbox populating code: DataTable copytable = null; copytable = GlobalTable.Copy(); // GlobalTable is a DataTable copytable.Rows[0][0] = "--ALL--"; copytable.Rows[0][1] = "--ALL--"; breakTypeList.DataSource = copytable; this.breakTypeList.DisplayMember = copytable.Columns[0].ColumnName; // description this.breakTypeList.ValueMember = copytable.Columns[1].ColumnName; // value this.breakTypeList.SelectedIndex = -1; I am setting description as the DisplayMember and

Loading text file into listbox

 ̄綄美尐妖づ 提交于 2019-11-30 09:23:42
问题 What I am wanting to achieve is loading a text file into a listbox. It seems simple enough but I need to recognise in the text file when there is a new line, and each new line needs to be a new item in the listbox. If this is possible, a reply would be much appreciated. 回答1: This will work List<string> lines = new List<string>(); using (StreamReader r = new StreamReader(f)) { string line; while ((line = r.ReadLine()) != null) { lines.Add(line); } } 回答2: OpenFileDialog f = new OpenFileDialog()