itemscontrol

WPF - Bind to Item Index from within ItemTemplate of ItemsControl?

混江龙づ霸主 提交于 2019-11-26 11:12:08
问题 Is there a way to bind to the ItemIndex from within the ItemTemplate of an ItemsControl? For example: <ItemsControl ItemsSource=\"{Binding Path=ItemList}\"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text=\"{Binding Path=ThisItemsIndex}\" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 回答1: If you're not using any type of alternating row styles you might be able to hijack the AlternationIndex for this. Set AlternationCount on your ItemsControl to something greater

How can a separator be added between items in an ItemsControl

半城伤御伤魂 提交于 2019-11-26 08:53:10
问题 I\'m needing to display a list of numbers from a collection in an Items Control. So the items are: \"1\", \"2\", \"3\" . When they are rendered, I need them separated by a comma (or something similar). So the above 3 items would look like this: \"1, 2, 3\" . How can I add a separator to the individual items, without having one tacked on the end of the list? I am not stuck on using an ItemsControl, but that\'s what I had started to use. 回答1: <ItemsControl ItemsSource="{Binding Numbers}">

Binding to custom control inside DataTemplate for ItemsControl

狂风中的少年 提交于 2019-11-26 08:37:29
问题 I have a problem with bindings for DataTemplate based on defined DataType in ItemsControl , when I want to bind to my custom user control . For demonstration purposes, I\'ve created simple Item class example, where I have collection of items like this: public class Item { public string ItemNameToBeSureWhatPropertyIsBound { get; set; } } In my ViewModel I create such collection, and expose it (with one item for comparison separately): public class MainWindowViewModel : INotifyPropertyChanged {

How to programmatically select an item in a WPF TreeView?

假如想象 提交于 2019-11-26 08:14:08
问题 How is it possible to programmatically select an item in a WPF TreeView ? The ItemsControl model seems to prevent it. 回答1: It's a real pain for some strange reason, you have to use ContainerFromItem to get the container, then invoke the select method. // selectedItemObject is not a TreeViewItem, but an item from the collection that // populated the TreeView. var tvi = treeView.ItemContainerGenerator.ContainerFromItem(selectedItemObject) as TreeViewItem; if (tvi != null) { tvi.IsSelected =

Finding control within WPF itemscontrol

喜夏-厌秋 提交于 2019-11-26 07:35:35
问题 Hi i have few a single textbox within the the datatemplate for itemscontrol. When i bind the itemcontrols to a observable collection i get two text boxes. But i need to do some manipulations based on each of the text boxes for which i want to find each textbox seperatly using some id. Can anybody help on how to find a control witin the itemscontrol in WPF. 回答1: Using the ItemContainerGenerator you can obtain the generated container for an item and traverse the visual tree downwards to find

Setting Canvas properties in an ItemsControl DataTemplate

狂风中的少年 提交于 2019-11-26 05:56:05
问题 I\'m trying to databind to this ItemsControl : <ItemsControl ItemsSource=\"{Binding Path=Nodes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}\"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> By using this DataTemplate , I\'m trying to individually position my Node elements on the Canvas correctly: <DataTemplate DataType=\"{x:Type Model:EndNode}\"> <Controls:EndNodeControl Canvas.Left=\"{Binding Path=XPos}\"

How do I do bindings in ItemContainerStyle in WinRT?

≯℡__Kan透↙ 提交于 2019-11-26 05:33:48
问题 I\'m trying to bind a collection to an ItemsControl, with a Canvas as the items panel, and with each item\'s Canvas.Left and Top bound to properties on the item objects. Basically I\'m trying to re-create the 2-D databinding I described in this post on my blog, but this time in WinRT instead of WPF. Since ItemsControl wraps your ItemTemplate content in another UI element (a ContentPresenter, in the case of WinRT), and it\'s those wrapper/container elements that are placed directly inside the

Virtualizing an ItemsControl?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-25 22:37:36
问题 I have an ItemsControl containing a list of data that I would like to virtualize, however VirtualizingStackPanel.IsVirtualizing=\"True\" does not seem to work with an ItemsControl . Is this really the case or is there another way of doing this that I am not aware of? To test I have been using the following block of code: <ItemsControl ItemsSource=\"{Binding Path=AccountViews.Tables[0]}\" VirtualizingStackPanel.IsVirtualizing=\"True\"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock