listbox

Listbox “IsSelected” binding only partially working

廉价感情. 提交于 2019-12-01 04:05:29
问题 I have a ListBox that I populate dynamically via a binding (this is defined in a DataTemplate , which is why the binding is somewhat unusual): <ListBox SelectionMode="Extended" ItemsSource="{Binding DataContext.ResultList, RelativeSource={RelativeSource AncestorType=Window}}"> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="IsSelected" Value="{Binding IsSelected}"/> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <Label

Cannot do key-value in listbox in C#

时光总嘲笑我的痴心妄想 提交于 2019-12-01 04:02:19
i'm writing a C# app using winforms. I have a listbox. I get my data from xml file, user name and their id's. I want names to be shown in the listbox and when I select one of them, I want to get his/her id using selectedValue property. However I cannot do this. I tried keyValuePair which shows "[username, id]" in the listbox which is not good (see code below). How can I simulate html select in c# in short? I want names to be shown in the listbox but want to get id's in the backend. Thanks... LB_UserList.Items.Add(new KeyValuePair<string, string>(full_name, node["user_id"].InnerText)); Chamika

wpf Listbox giving columns a header

限于喜欢 提交于 2019-12-01 03:58:34
I have the following markup (xaml): <ListBox Name="lbEurInsuredType" HorizontalContentAlignment="Stretch"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="0,2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="30"></ColumnDefinition><ColumnDefinition Width="2"></ColumnDefinition> <ColumnDefinition Width="30"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Title}"></TextBlock> <TextBox Text="{Binding Uw}" Grid.Column="1"></TextBox> <TextBox Text="{Binding Partner}" Grid.Column="3"></TextBox> </Grid> </DataTemplate><

Listbox item WPF, different background color for different items

百般思念 提交于 2019-12-01 03:32:28
I have a WPF ListBox containing a binded list of items from a specific class that I have. Something like this: ObservableCollection<MyTable> tables = new ObservableCollection<MyTable>(); ... listTables.ItemsSource = tables; And the XAML: <ListBox HorizontalAlignment="Left" Margin="8,10,0,0" Name="listTables" Width="153" ItemsSource="{Binding tables}" SelectionChanged="listTables_SelectionChanged" Height="501" VerticalAlignment="Top"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="1"> <TextBlock Grid.Column="1" Text="{Binding tableName}" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> <

How can I set the focus to a ListBox properly on load if it uses databinding?

做~自己de王妃 提交于 2019-12-01 03:04:07
问题 I usually call myControl.Focus() in the Loaded event handler, but this doesn't seem to work for a ListBox which is databound to a list of custom objects. When I start my application, the ListBox 's first item is selected but the focus is elsewhere. I thought this could be because the focus is being set before the databound items are loaded into it... but the following code shows that there are indeed items because ctrlItemsCount shows the number 8. How can I set the initial focus in this

WPF ListBox - Getting UIElement instead of of SelectedItem

邮差的信 提交于 2019-12-01 02:44:31
I created a ListBox that has a DataTemplate as Itemtemplate . However, is there an easy way to access the generated UIElement instead of the SelectedItem in codebehind? When I access SelectedItem , I just get the selected object from my ItemsSource collection. Is there a way to access the UIElement (ie. the element generated from the DataTemplate together with the bound object)? Szymon Rozga You are looking for the ItemContainerGenerator property. Each ItemsSource has an ItemContainerGenerator instance. This class has the following method that might interest you: ContainerFromItem(object

Programmatically selecting Items/Indexes in a ListBox

痴心易碎 提交于 2019-12-01 02:40:55
In WPF, I'd like to set the selected indexes of a System.Windows.Controls.ListBox I best way I've found so far is to remove all the items from the control, insert the selected, call SelectAll(), then insert the rest, but this solution neither works in my situation nor is very efficient. So, how do you set items in a Listbox to be selected, programmatically? One way you can do this is to add a Selected field to your data object. Then you need to overide the default listboxitem style and bind the isselected property to the Selected property in your object. Then you just need to go through your

C# Force ListBox to update elements

爱⌒轻易说出口 提交于 2019-12-01 02:09:26
问题 I'm subclassing the standard ListBox control. I get notified of changes to any of the elements added to the list. The task is to update the text shown by the ListBox for the changing element. I'm aware that i could just remove the changed element and add it again, but this seems not preferable for obvious reasons. 回答1: Unfortunately, the data-binding in ListView doesn't support regular (item) change notification events ( FooChanged / INotifyPropertyChanged ). However, if you know about the

How to use IsKeyboardFocusWithin and IsSelected together?

烈酒焚心 提交于 2019-12-01 02:05:59
问题 I have a style defined for my ListBoxItems with a trigger to set a background color when IsSelected is True: <Style x:Key="StepItemStyle" TargetType="{x:Type ListBoxItem}"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border Name="Border" Padding="0" SnapsToDevicePixels="true"> <ContentPresenter /> </Border> <ControlTemplate.Triggers>

How can I change the text of Listbox item?

只谈情不闲聊 提交于 2019-12-01 01:46:01
问题 I have a Listbox full of items, and I need to change an item's text. Using item configure I can only find out how to change colors. How can I change the item text on a Tkinter Listbox ? 回答1: To change the text you will have to delete and re-add an item at the proper index. Here is a contrived example that continuously updates the second item in the listbox: import Tkinter as tk import time class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) self.lb = tk