listbox

How to implement Hold in Listbox?

懵懂的女人 提交于 2019-11-30 22:05:45
If hold the listbox, I want to get listbox index. This is my code: <ListBox Margin="0,0,-12,0" Hold="holdlistbox" x:Name="listbox" SelectionChanged="listbox_SelectionChanged" SelectedIndex="-1"> </ListBox> private void holdlistbox(object sender, System.Windows.Input.GestureEventArgs e) { //How to get ListBox index here } If anyone knows help me to do this. e.OriginalSource will get you the actual control that was held (the top-most control directly under your finger). Depending on your ItemTemplate and where you hold then this could be any of the controls in the item. You can then check the

How can I realize SelectionChanged in MVVM ListBox Silverlight

余生长醉 提交于 2019-11-30 21:20:46
The ListBox control does not implement a Command property. I have to attach some functionality to the SelectionChanged event. Somebody knows how can I do it? Please help me I prefer using a binding to the SelectedItem and implementing any functionality in the setting of the binding property. <ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" /> ... public class ViewModel { public IEnumerable<Item> Items { get; set; } private Item selectedItem; public Item SelectedItem { get { return selectedItem; } set { if (selectedItem == value) return; selectedItem = value; // Do

How to get selected items from listbox has checkboxes in WPF?

青春壹個敷衍的年華 提交于 2019-11-30 21:15:26
This is the ListBox code: <ListBox x:Name="courseslistview" ItemsSource="{Binding .}" FontSize="18.667" FontFamily="Trebuchet MS" LayoutUpdated="courseslistview_LayoutUpdated"> <ListBox.ItemTemplate> <DataTemplate> <CheckBox Content="{Binding .}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> How can I use C# to get all the checked checkboxes in the above ListBox? CodeNaked It would probably be best to bind the CheckBox to the IsSelected property of the ListBoxItem , like so: <DataTemplate> <CheckBox Content="{Binding .}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=

Listbox scrollbar thumb changes size when content is variable height

為{幸葍}努か 提交于 2019-11-30 21:08:29
I have a ListBox with many objects displayed, each of which can be a variable height, based on the number of values each object has. See my previous question that was answered here. Many objects are 5-lines high, while others are 1. The scroll bar in the ListBox does not appear to like this, probably due to the virtualization. While you scroll through, the thumb on the scroll bar will change its size , based on how many items are actually fitting into the box at that current moment. This makes the thumb very big at times, and very small at other times. Since this ListBox is also contained

Parse XML and populate in List Box

六月ゝ 毕业季﹏ 提交于 2019-11-30 21:06:55
问题 I'm a newbie to C#. I want to develop C# List box in Windows Form. I found this link to be helpful. But the input to the List box will be an XML of the following format: <LISTBOX_ST> <item><CHK></CHK><SEL>00001</SEL><VALUE>val01</VALUE></item> <item><CHK></CHK><SEL>00002</SEL><VALUE>val02</VALUE></item> <item><CHK></CHK><SEL>00003</SEL><VALUE>val03</VALUE></item> <item><CHK></CHK><SEL>00004</SEL><VALUE>val04</VALUE></item> <item><CHK></CHK><SEL>00005</SEL><VALUE>val05</VALUE></item> </LISTBOX

Keyboard focus to list box items in WPF [duplicate]

懵懂的女人 提交于 2019-11-30 20:43:19
问题 This question already has answers here : WPF ListBoxItem selection problem (3 answers) Closed 5 years ago . I am having a list box, and its item template is having one check box. Now, when I click on the check box in the listbox, it sets the checked status of the check box. If I use keyboard "Space" key, I cannot change the checkbox state. Note: Keyboard is shortcut is working once I set focus to the check box by clicking it. 回答1: If you don't want the ListBox to provide selection at all, you

Windows.Forms.ListBox with OwnerDrawVariable bug?

爷,独闯天下 提交于 2019-11-30 20:42:49
问题 In a Windows.Forms.ListBox with the property DrawMode set to OwnerDrawVariable , the ListBox seems to cache the height of the items, what is good. BUT, being the item height dependent of the width, because it uses Graphics.MeasureString to do word wrap, needs to calculate the height of items if the size of the ListBox has changed. Then there's a problem. The ListBox doesn't do this by default, and I can't find a method to clear the cache, forcing the ListBox to raise the itemheight event. Any

Lazy loading of listbox images from isolated storage

穿精又带淫゛_ 提交于 2019-11-30 20:37:10
I have lots of images stored in isolated storage and want to display them in a listbox. However, I don't want all images to be loaded right away but lazily. So only when the user scrolls to see new items the images should be loaded. I also want to use data binding for providing the list item's data and image. In the tests I did all images always got loaded right away and at once, so I am unsure whether this lazy loading can be achieved with the default ListBox and data binding. Can it? You can use the standard ListBox to "lazy load" your items with databinding. The keyword here is "data

Can't convert ListBox.ObjectCollection to a (typed) array

Deadly 提交于 2019-11-30 20:16:57
I want to convert the items to a String array or the type that I used to fill the ListBox.DataSource. The type has overridden ToString() but I can't seems to get it converted, not even to String[]. String[] a = (String[])ListBox1.Items; Contacts[] b = (Contacts[])ListBox1.Items; string[] a = ListBox1.Items.Cast<string>().ToArray(); Of course, if all you plan to do with a is iterate over it, you don't have to call ToArray(). You can directly use the IEnumerable<string> returned from Cast<string>() , e.g.: foreach (var s in ListBox1.Items.Cast<string>()) { do_something_with(s); } Or, if you have

c# wpf - cannot set both DisplayMemberPath and ItemTemplate

三世轮回 提交于 2019-11-30 20:09:10
I want to add tooltip in listboxItem but it starts problem when there is DisplayMemberPath. Error message said: cannot set both DisplayMemberPath and ItemTemplate. When I removed DisplayMemberPath, tooltip in each list item is working. But i dont want to remove DisplayMemember because i need it. How to solve this problem? <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}" ItemsSource="{Binding Strings}" DisplayMemberPath="Toys" MouseDoubleClick="lstToys_MouseDoubleClick"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}" ToolTip="Here is a tooltip"/> <