Questions tagged [itemssource]

362 questions
42
votes
10 answers

ItemContainerGenerator.ContainerFromItem() returns null?

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…
Sonny Boy
  • 7,244
  • 16
  • 67
  • 101
36
votes
2 answers

Why are DataContext and ItemsSource not redundant?

In WPF Databinding, I understand that you have DataContext which tells an element what data it is going to bind to and ItemsSource which "does the binding". But e.g. in this simple example it doesn't seem that ItemsSource is doing anything useful…
Edward Tanguay
  • 176,854
  • 291
  • 683
  • 1,015
23
votes
3 answers

Custom ItemsSource property for a UserControl

Does anyone know how to make a custom ItemsSource? What I want to do is to make an itemsSource to my own UserControl so that it could be bound by ObservableCollection<>. Also, I could know Whenever the number of items in the itemsSource updated, so…
user1184598
  • 429
  • 1
  • 4
  • 10
22
votes
1 answer

Difference between ItemsSource and DataContext as pertains to ListBox

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…
AngryHacker
  • 54,471
  • 90
  • 289
  • 523
20
votes
2 answers

How to setup a grid as template for an Items control?

I'm trying to create an ItemsControl that uses a grid as its ItemsPanel in such a way that it has two columns, where the first columns width is the width of the widest item in that column, and has as may rows needed to display all the…
pastillman
  • 984
  • 1
  • 12
  • 24
18
votes
5 answers

WPF - reset ListBox scroll position when ItemsSource changes

I currently have a ListBox whose ItemsSource collection is bound to a property on my viewmodel, of type IEnumerable. When that preoprty's reference changes, the ListBox updates as expected, however I have a problem in that if I have a large…
devdigital
  • 33,472
  • 8
  • 93
  • 117
14
votes
3 answers

set xaml code ItemsSource="{Binding}" with code behind

I have the following property Temp2: (my UserControl implements INotifyPropertyChanged) ObservableCollection _Temp2; public ObservableCollection Temp2 { get { return _Temp2; } …
Tono Nam
  • 29,637
  • 73
  • 252
  • 421
13
votes
1 answer

WPF - Combobox SelectedItem not getting set?

I have a ComboBox that has its ItemsSource bound to a static List 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…
Rachel
  • 122,023
  • 59
  • 287
  • 465
11
votes
1 answer

WPF Binding ItemsSource to a static method?

I have the following static method in an class called "Article" : public static ObservableCollection
GetObservableCollection() { ... } And I'd like to bind this directly to the ItemsSource property of a ComboBox but in the XAML not in…
Karnalta
  • 508
  • 1
  • 9
  • 24
11
votes
1 answer

IsSynchronizedWithCurrentItem attribute and current item updates

I have a view model to manage a dialog type of view that allows filtering of a listing (if necessary) and selection of an item. The code works fine whether I set IsSynchronizedWithCurrentItem to true or not. My understanding is that this property is…
Berryl
  • 11,796
  • 21
  • 88
  • 170
11
votes
6 answers

WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections

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…
Partial
  • 8,263
  • 12
  • 39
  • 57
10
votes
3 answers

Binding to DataContext outside current ItemsSource context

I have a DataSet bound to the Window.DataContext; I also have a DataGrid:
vuduy
  • 111
  • 1
  • 1
  • 5
10
votes
1 answer

IEnumerable property without type

I'm trying to make a property like the official DataGrid.ItemsSource, from MSDN: public IEnumerable ItemsSource { get; set; } This provides the support of any type, in any derived class. With this, I can set something like var list = new…
Guilherme
  • 4,518
  • 4
  • 33
  • 52
10
votes
3 answers

Keeping Focus/SelectedItem after DataGrid ItemsSource change

ive been working on this for a few days, but cant seem to come up with a solution i have code on a timer that refreshes the DataGrid every few seconds i tried many refresh options, but in the end they all lose the users focus and sometimes also the…
Yisroel M. Olewski
  • 1,266
  • 1
  • 23
  • 35
9
votes
3 answers

Change ListBox.ItemsSource Binding property on Button.Click?

Quick question... I have a ListBox with its ItemsSource property bound to a collection property in a viewmodel like so: I also have two Button objects in the same…
Sheridan
  • 64,785
  • 21
  • 128
  • 175
1
2 3
24 25