itemscontrol

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, we want to move the selection programattically and not allow the user to change it. Is t...

Find UI element corresponding to an item in a Silverlight ItemsControl

I have a list of strings displayed by a Silverlight ItemsControl. The DataTemplate is a Border control with a TextBlock as its child. How can I access the border control corresponding to an item? For example, I might want to do this to change the background color. ...

How do I get the instance of a templated item from a databound ItemsControl? (WPF)

I have an <ItemsControl> with a custom <DataTemplate> (and also a custom <ItemsPanelTemplate> that is just a WrapPanel), bound via ItemsSource to a simple observable collection of strings. The DataTemplate consists simply of an instance of a custom UserControl whose properties are bound to the string via {Binding}. The problem is since...

What WPF book covers GetContainerForItemOverride and related in detail?

What WPF book covers ItemsControl.GetContainerForItemOverride and related in detail? Additionally I would like to read about why TreeView overrides it and how IsItemItsOwnContainerOverride is related to it. ...

WPF Datatemplating an ItemsControl

I have an ItemsControl whose ItemsSource gets bound to an ObservableCollection<Component> at run time. I have defined a data template for type Component which works fine. Now Component has a ObservableCollection<Control> and I want to add another ItemsControl inside my Component Datatemplate to render all the controls. Control here is ...

Silverlight ItemsControl. Can you remove the panel completely via templating?

I have a DataTamplate for my ItemsControl that merely contains an Image with some other meta data. What I am trying to do is bind to the ItemsControl and have the Images be displayed with the Convas.Left and Canvas.Top that is bound via the data I give. I have been trying my best to remove any Panels from the control via the ItemsPanel...

How do I Monitor changes in an ItemsControl using Silverlight?

I have an ItemsControl bound to an ObservableCollection. When the observable collection changes, I have an event handler that looks at the children of the ItemsControl. Unfortunately, the ItemsControl hasn't yet added a new item at that time (which is understandable). How can I know when an ItemsControl has finished adding new child cont...

WPF: Changing a groupstyle panel at runtime

I am using an ItemsControl bound to a CollectionViewSource. I set its ItemsPanel to a WrapPanel (with orientation initially set to horizontal) and am using a button to toggle between horizontal and vertical orientation. Basically changing the ItemsPanel to point at different resources, inside the button click handler. This works fine. ...

WPF - ItemsControl - How do I get find my "CheckBox" item that is in the ItemTemplate?

I have the following (very simple) ItemsControl: <ItemsControl Name="BlahList" ItemsSource="{Binding Blah}"> <ItemsControl.ItemTemplate> <DataTemplate> <CheckBox Name="MyCheckBox" Content="{Binding Text}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> In code, I would like to do the following: ...

Forcing WPF to create the items in an ItemsControl

I want to verify that the items in my ListBox are displayed correctly in the UI. I figured one way to do this is to go through all of the children of the ListBox in the visual tree, get their text, and then compare that with what I expect the text to be. The problem with this approach is that internally ListBox uses a VirtualizingStackP...

Silverlight 2: Want a variable number of items to take up a fixed width.

The stackpanel is not co-operating. We have a fixed width, and a variable number of items to lay out left-to-right inside it. We have a an items control that lays them out with a stack panel: <ItemsControl x:Name="testItems" HorizontalAlignment="Left" VerticalAlignment="Top"> <ItemsControl.ItemsPanel> ...

WPF - Creating a custom ItemsControl

I'm looking into creating custom controls for WPF and I've found some reasonably useful blogs and such that vaguely go into enough detail but I'm still struggling a bit. Basically, what I'm trying to create is something akin to the infamous 'Coda Slider' but i just don't know enough to get started properly. Can anyone either point me i...

WPF - UserControl default Content attribute

I'm creating a UserControl and I just can't remember the name of the attribute which you use to decorate the property which you want to act as the default content property. To give a concrete example, say i have a property called 'Title' which i can set using property syntax like this - <local:myControl Title="the title"/> But the...

WPF: Aggregating properties on a ListBox

I have two ListBoxes, both use Extended SelectionMode. The ItemsSource of the first is a List, and uses a datatemplate. I'm trying to use an aggregation of some property from the first as the itemssource for the second. For example: public class MultiAppPropertyAggregator : IValueConverter { public object Convert(object value, T...

WPF GridViewRowPresenter in an ItemsControl

I'm just starting learning WPF and I'm trying to use a GridViewRowPresenter inside of an ItemsControl to essentially duplicate the functionality of a simple table in HTML. The ListView is not appropriate since it is interactive (which I don't want). I am binding to a generic List of objects of an unknown quantity. I have a List of a cus...

In WPF/Silverlight is it possible to bind to an HTML-like TableControl?

...

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 state it isn't 2D yet). I databind an ItemsControl to an ObservableCollection<Square>, where...

WPF ItemsControl data binding - adding extra initial controls

I have the following XAML for a databound items control to show a list of groups, with a label and button to add a new group appearing first: <WrapPanel Orientation="Horizontal"> <Label Content="Groups" /> <Button x:Name="btnGroupAdd" Click="btnGroupAdd_Click" Content="+" /> <ItemsControl ItemsSource="{Binding}" x:Name="_groupList" >...

Why does ItemsControl show a focus rectangle when its parent is focused?

WPF's ItemsControl will display a focus rectangle when it thinks it has focus and the user presses Tab or Alt. But I recently had an ItemsControl display a focus rectangle even though it did not have focus -- one of its parents did. The ItemsControl was inside a UserControl, which was inside another UserControl that did have focus. Some...

How do I use a Silverlight2 ItemsControl to position a collection of items on a canvas?

In WPF, you can create a ListBox with a Canvas as an ItemsPanel and position items on that canvas. The code to do that looks something like this: <ListBox ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name}"/> </DataTemplate> </ListBox.ItemTemplate> ...