itemssource

WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections

北城以北 提交于 2019-11-27 07:01:35
Situation: I've created a DataGrid in XAML and the ItemsSource is binded to an ObservableCollection of a certain class that contains properties. Then in C#, I create a DataGridTextColumn and a DataGridComboBoxColumn and binded these to the properties of the objects inside the ObservableCollection. I can bind the DataGridComboBoxColumn to a simple Collection but what I want to do is bind it to a collection of collections of strings so that for each row the ComboBox inside the DataGrid has a different collection of string. I have failed to do so... Question: How can I bind the

Difference between ItemsSource and DataContext as pertains to ListBox

狂风中的少年 提交于 2019-11-27 05:25:26
问题 I am not quite grokking the difference between ItemsSource and DataContext. Can someone explain it and back it up with examples? When would I use one or the other. I am reading the docs and it says that I can bind using DataContext, but I throw an ObservableCollection at it and nothing shows up in the list. If I throw the same collection at the ItemsSource, it works fine. 回答1: Controls (including the ListBox) don't do anything with the value of DataContext at all. Its purpose is to provide a

Display properties of the ListBox.ItemsSource

好久不见. 提交于 2019-11-26 22:27:16
问题 I am new to WPF. I have a ListBox that has its ItemSource set to a instance of WorkItemCollection. (A collection of WorkItem objects.) When the list is displayed it only displays the type of each object (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem). Is there a way to make the list display WorkItem.Title? 回答1: You have two options. The simplest method is to set the DisplayMemberPath property of your ListBox to "Title". If you want to set not only what gets displayed, but the type

WPF - Combobox SelectedItem not getting set?

狂风中的少年 提交于 2019-11-26 21:48:16
问题 I have a ComboBox that has its ItemsSource bound to a static List<CustomSettings> of options. The ComboBox is part of a form which is bound to a CustomObject class, and one of the properties on that class is a CustomSettingProperty. I would like to bind the SelectedItem of the ComboBox to the property specified in the CustomObject, however SelectedItem="{Binding Path=CustomSettingProperty}" is not setting the default selected item. Using breakpoints I can see that it is calling the get;

ItemContainerGenerator.ContainerFromItem() returns null?

谁都会走 提交于 2019-11-26 20:52:30
I'm having a bit of weird behavior that I can't seem to work out. When I iterate through the items in my ListBox.ItemsSource property, I can't seem to get the container? I'm expecting to see a ListBoxItem returned, but I only get null. Any ideas? Here's the bit of code I'm using: this.lstResults.ItemsSource.ForEach(t => { ListBoxItem lbi = this.lstResults.ItemContainerGenerator.ContainerFromItem(t) as ListBoxItem; if (lbi != null) { this.AddToolTip(lbi); } }); The ItemsSource is currently set to a Dictionary and does contain a number of KVPs. Phred Menyhert I found something that worked better

ItemContainerGenerator.ContainerFromItem() returns null?

点点圈 提交于 2019-11-26 07:46:41
问题 I\'m having a bit of weird behavior that I can\'t seem to work out. When I iterate through the items in my ListBox.ItemsSource property, I can\'t seem to get the container? I\'m expecting to see a ListBoxItem returned, but I only get null. Any ideas? Here\'s the bit of code I\'m using: this.lstResults.ItemsSource.ForEach(t => { ListBoxItem lbi = this.lstResults.ItemContainerGenerator.ContainerFromItem(t) as ListBoxItem; if (lbi != null) { this.AddToolTip(lbi); } }); The ItemsSource is