Questions tagged [itemscontrol]

Represents a control that can be used to present a collection of items.

An ItemsControl is a type of WPF Control that can contain multiple items, such as strings, objects, or other elements.

1200 questions
17
votes
5 answers

WPF ItemsControl the current ListItem Index in the ItemsSource

Is it possible to know the current item's Index in a ItemsControl? EDIT This works! One Two
Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
17
votes
1 answer

ItemsControl ItemTemplate Binding

In WPF4.0, I have a class that contains other class types as properties (combining multiple data types for display). Something like: public partial class Owner { public string OwnerName { get; set; } public int OwnerId { get; set;…
Wonko the Sane
  • 10,623
  • 8
  • 67
  • 92
17
votes
2 answers

Item spacing in WPF ItemsControl

I'm displaying a List collection in an ItemsControl. The problem is that there is no spacing between the list items such as TheyAreAllNextToEachOther. How can I create some spacing between the items?
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
16
votes
3 answers

When using ItemsControl ItemsControl.ItemsPanel is set to Canvas, ContenPresenter comes in and break my Canvas properties on the children [WPF]

I am using an ItemsControl where the ItemsPanel is set to Canvas (see this question for more background information). The ItemsControl is performing as I want, and it works like a charm when adding a child element manually by putting it into…
code-zoop
  • 7,312
  • 8
  • 47
  • 56
15
votes
1 answer

Bind the height of a grid row to it's contents in WPF

I have a grid with a few rows. In the top row, I have an ItemsControl that is bound dynamically to a collection and uses a DataTemplateSelector and ItemsPanelTemplate (with a single horizontally arranged WrapPanel). Here's a stripped-down version…
Rich
  • 36,270
  • 31
  • 115
  • 154
15
votes
1 answer

Update ItemsControl when an item in an ObservableCollection is updated

The Problem: You declare an ItemsControl ( or a control derived from ItemsControl) in the view. You bind the ItemsControl.ItemsSource property to an ObservableCollection in your ViewModel. Your view updates as expected when an item is added to…
Frank Liu
  • 1,466
  • 3
  • 23
  • 36
15
votes
3 answers

ItemsControl missing vertical scrollbar

I have the below ItemsControl which wraps items perfectly but it does not have a vertical scrollbar to see the wrapped items. How can I get the scrollbar to show?
touyets
  • 1,315
  • 6
  • 19
  • 34
15
votes
4 answers

Can a WPF ListBox be "read only"?

We have a scenario where we want to display a list of items and indicate which is the "current" item (with a little arrow marker or a changed background colour). ItemsControl is no good to us, because we need the context of "SelectedItem". However,…
Matt Hamilton
  • 200,371
  • 61
  • 386
  • 320
14
votes
4 answers

ItemsControl button click command

I need some quick help which is a road blocker for me now. I have Button in ItemsControl and I need to perform some task on Button click. I tried adding Command to Button in ItemsControl DataTemplate but its not working. Can anyone suggest how to…
user1095239
  • 183
  • 1
  • 3
  • 8
14
votes
2 answers

How to dynamically add RowDefinition or ColumnDefinition to a Grid with binding?

I'm trying to create a table with a variable number of rows and columns. I'm doing this with an ItemsControl which has a Grid as its ItemsPanel. And I know I can set Grid.Row and Grid.Column of each item through its ItemContainerStyle. But I don't…
Bizhan
  • 16,157
  • 9
  • 63
  • 101
14
votes
1 answer

Multiple user controls share collection dependency property

I have implemented my own usercontrol based on listboxes. It has a dependency property with type of a collection. It works fine when I have only one instance of the usercontrol in a window, but if I have multiple instances I get problem that they…
Wallstreet Programmer
  • 9,567
  • 3
  • 37
  • 52
13
votes
3 answers

Selecting DataTemplate based on sub-object type

I want to databind an ItemsCollection, but instead of rendering the collection items, I want to render sub-objects reached via a property on the collection item. To be more specific: this will be a 2D map viewer for a game (though in its current…
Joe White
  • 94,807
  • 60
  • 220
  • 330
13
votes
2 answers

Style within DataTemplate is only being applied to the last item in ItemsControl?

In the XAML below, I have an ItemsControl that has three DataObjects. I use a DataTemplate to display DataObjects as Buttons with an "X" on them. The Button uses a Style to set its Content. If the Setter.Value is "X", everything works…
Scott
  • 11,840
  • 6
  • 47
  • 54
13
votes
2 answers

Why Does ItemsControl Not Use My ItemTemplate?

I am able to use an ItemTemplate within an ItemsControl to render items in a specific format. However, if one of the items within the ItemsControl happens to be, say, a TextBox, that TextBox is rendered rather than an instance of the ItemsTemplate.…
Drew
  • 817
  • 1
  • 11
  • 17
13
votes
2 answers

Why does the Parent property of a container of an ItemsControl return null and not the Panel it sits on?

This one has me stumped. We have a custom ItemsControl which uses both custom containers as well as a custom panel as its ItemsHost. Now the panel has some metrics that the containers need for rendering purposes. Since they are direct children of…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
1 2
3
79 80