listbox

WPF ContextMenu bound to 3 Listboxes on right-click

▼魔方 西西 提交于 2019-12-12 04:22:34
问题 I have three tabs and each has a listbox with different types of files. When I right-click on an item in the listbox, I want a ContextMenu with "New, Edit and Delete" as Item headers. I guess I could have a ContextMenu for each listbox, and then have a seperate method for each header, such as: <ListBox.ContextMenu> <ContextMenu x:Name="NewEditDeleteAdvCalcFileContextMenu"> <MenuItem Name="NewAdv" Header="New" Click="NewAdv_Click" /> <MenuItem Name="EditAdv" Header="Edit" Click="EditAdv_Click"

C# removing the current item in a listbox

让人想犯罪 __ 提交于 2019-12-12 04:14:47
问题 I have a List which holds a bunch of objects, the contents of the list is then added to a listbox control. My question is, how can I remove the current item in the list which will in turn remove the current item in the listbox? 回答1: you can just get the selected index in the selectedindex_changed event handler, remove the object at that index and repopulate the listbox int index = listbox.SelectedIndex(); listThatHoldsObjects.RemoveAt(index); listbox.ItemsSource = listThatHoldsObjects 回答2:

Disable ListBox items

删除回忆录丶 提交于 2019-12-12 04:08:53
问题 As far as I know, there is no way to grey out/disable specific items in the ListBox control? I want to make a list of surveys that need to be answered, but grey out/disable those that the user has already answered. Anyone got some advices how I should do this? Or is there some way to do it with ListBox? 回答1: You will need to do custom drawing to handle this. Look up OwnerDraw The typical (and simpler) pattern is just to not include those items in the ListBox. An alternative would be to use

Constraining item heights in WPF ListBox, with indicator

[亡魂溺海] 提交于 2019-12-12 04:06:07
问题 I have a ListBox control in WPF which contains items of variable height (predominantly a large text block, so it's also affected by word wrapping). Since scrolling behaves badly when the height of an individual item gets too high (especially when close to the height of the ListBox itself), I want to constrain the max height of the individual items. I've done that readily enough, by using a Style to set the MaxHeight of the ListBoxItem container. My problem is that I would like to detect that

DataTrigger not changing template in ItemContainerStyle for Listbox

旧时模样 提交于 2019-12-12 03:52:54
问题 my idea is to change appearance of ListboxItem when MouseOver or Button is clicked etc. <ListBox Name="listbox" Height="250" Grid.Row="4" Grid.ColumnSpan="5" HorizontalAlignment="Center"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Template" Value="{StaticResource control_mouseover}" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Template" Value="{StaticResource

Get items values of ListBox with SelectedIndex

依然范特西╮ 提交于 2019-12-12 03:52:52
问题 I've got for example ListBox with two TextBlock s like this: <ListBox Name="listboxNews" SelectionChanged="listboxNews_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Width="400" Height="70"> <TextBlock Text="{Binding Title}" name="title" /> <TextBlock Text="{Binding Description}" name="desc" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> And as you can see, I've got listboxNews_SelectionChanged method, in which i need to select Text of first

How do I populate the listbox plugin item Name as it is set in the Plugin interface?

扶醉桌前 提交于 2019-12-12 03:52:07
问题 When the plugin buttons get loaded, the button gets populated with the name of the IPlugin Interface as it asks in the method string Name { get; } I’m trying to get the listbox item to populate with the name the same way its doing so for the button. private void AssembleComponents private void AssembleComponents(object sender) { ICollection<IPlugin> plugins = GenericPluginLoader<IPlugin>.LoadPlugins("Plugins"); string selection = ""; if (sender is ListBox) { if (((ListBox)sender)

Data Binding list to listbox C# XAML (Azure mobile services) UWP

允我心安 提交于 2019-12-12 03:49:02
问题 So I have an online database. And I want the query results to be displayed in a listbox. I tried to use data binding but I think I'm doing it totally wrong. Files [![enter image description here][1]][1] Table class ProductTable { public string id { get; set; } public string Name { get; set; } public string Title { get; set; } public string Description { get; set; } public double Price { get; set; } public string Type { get; set; } public string Seller { get; set; } public int Expiration { get

How to know when a ListBoxItem comes into view?

风格不统一 提交于 2019-12-12 03:27:53
问题 Is there an event that tells me when a list box item comes into view? The problem I have is that I can have several thousand elements that I set as my ListBox.ItemSource . Each element will generate a bitmap (which takes a while) so if I would just put this bitmap generation in the constructor creating the collection would take forever to create. Instead I want to defer the bitmap generation when an item comes into view. Is there a way to do this? Ideally I would prefer not to loop through

How can I remove more than one item from a listbox?

…衆ロ難τιáo~ 提交于 2019-12-12 03:25:40
问题 This is really getting annoying; or, to be honest, it became quite annoying a good while back. Programmatically removing items from a listbox should be pretty straightforward, yet it seems everything I try ends up the same: with an exception. This time it's "InvalidOperationException". In context (excerpt of log file): Date: 2/12/2015 7:15:17 PM Message: Reached frmMain.UpdateGUIAfterTableSend Date: 2/12/2015 7:15:17 PM Message: From frmMain.SendDeliveries(): InvalidOperationException; Inner