itemscontrol

Forcing WPF to create the items in an ItemsControl

柔情痞子 提交于 2019-12-01 02:23:52
问题 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 VirtualizingStackPanel to display its items, so only the items that are visible are created. I eventually came across the ItemContainerGenerator class, which looks like it

WPF UserControl in DataTemplate within ItemsControl - how to bind to parent of ItemsSource

独自空忆成欢 提交于 2019-12-01 01:47:22
问题 The subject line says it all really! I have a user control which can be bound successfully to, say, a Fullname object - i.e. it works ok. I now need to show a list of these and, again, this works ok when the control is in a DataTemplate within ItemsControl.Template. But, the control has a property (InEditMode) that is not a property of the Fullname object but of the object that has the FullnameList property to which the ItemsControl is bound, via ItemsSource. This InEditMode property works

How can I create a Grid with it's X and Y axis bound to different collections?

元气小坏坏 提交于 2019-12-01 01:28:05
I need to display something that shows a Week of days along the Columns, and a list of Categories along the Rows, and a list of Tasks that are due in the Cells (See sketch below) I feel like the solution should be simple, but I'm drawing a blank as to how to bind such a thing. Both the Rows, Columns, and data items in the Cells are dynamic based on what week the user is viewing, and ideally I'd like to hide categories that do not have any tasks for the currently viewed Week. I have collection properties for the currently Viewed Week, the list of Categories, and the list of Tasks, and each Task

Dragable objects in WPF in an ItemsControl?

好久不见. 提交于 2019-11-30 21:33:11
I want to be able to implement an ItemsControl with dragable items. The reason for the ItemsControl is so I can bind to my ViewModel in the background. I've tried using a Thumb Control in a canvas and it works perfect, except as soon as I stick it in an ItemsControl it stops working. Here is what I tried: <ItemsControl ItemsSource="{Binding MyItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <Thumb Canvas.Left="0" Canvas.Top="0" Width="50" Height="50" DragDelta="MyThumb_DragDelta"/> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> <

How can I create a Grid with it's X and Y axis bound to different collections?

我的未来我决定 提交于 2019-11-30 21:21:34
问题 I need to display something that shows a Week of days along the Columns, and a list of Categories along the Rows, and a list of Tasks that are due in the Cells (See sketch below) I feel like the solution should be simple, but I'm drawing a blank as to how to bind such a thing. Both the Rows, Columns, and data items in the Cells are dynamic based on what week the user is viewing, and ideally I'd like to hide categories that do not have any tasks for the currently viewed Week. I have collection

Listbox scrollbar thumb changes size when content is variable height

為{幸葍}努か 提交于 2019-11-30 21:08:29
I have a ListBox with many objects displayed, each of which can be a variable height, based on the number of values each object has. See my previous question that was answered here. Many objects are 5-lines high, while others are 1. The scroll bar in the ListBox does not appear to like this, probably due to the virtualization. While you scroll through, the thumb on the scroll bar will change its size , based on how many items are actually fitting into the box at that current moment. This makes the thumb very big at times, and very small at other times. Since this ListBox is also contained

How do I access the children of an ItemsControl?

二次信任 提交于 2019-11-30 08:02:43
If i have a component derived from ItemsControl , can I access a collection of it's children so that I can loop through them to perform certain actions? I can't seem to find any easy way at the moment. A solution similar to Seb's but probably with better performance : for(int i = 0; i < itemsControl.Items.Count; i++) { UIElement uiElement = (UIElement)itemsControl.ItemContainerGenerator.ContainerFromIndex(i); } Seb Nilsson See if this helps you out: foreach(var item in itemsControl.Items) { UIElement uiElement = (UIElement)itemsControl.ItemContainerGenerator.ContainerFromItem(item); } There is

ItemsControl.ItemsSource MVVM performance

≯℡__Kan透↙ 提交于 2019-11-30 05:27:04
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel instances. Now once the large amount Model instances is loaded all the ViewModel complemnents needs to be added to that ObservableCollection. How can I add a large amount of ViewModels without making the UI Thread hang? I suppose the UI Thread hangs because each time a new item is added the ItemsControl needs to update itself and does layout etc. over and over again. Should I suspend the binding add all items and then resume? If so, how? Should I override the ObservableCollection to

What exactly does Panel.IsItemsHost do?

随声附和 提交于 2019-11-30 01:23:17
I cannot find any good documentation for the Panel.IstItemsHost attached property. I see plenty of examples of people setting it on the ItemsContainer template for an ItemsControl, but the un-documentation over at MSDN does not explain why or what advantages setting property confers. I have built plenty of containers that do NOT set this property, but have not yet noticed any ill effects. Say I have an ItemsControl. I want to use a custom panel that swoops items in and out as you scroll; its called a SwoopPanel. Now, how do I tell the ItemsControl to use my SwoopPanel to contain the templates

How to draw line of ten thousands of points with WPF within 0.5 second?

℡╲_俬逩灬. 提交于 2019-11-29 19:59:26
I am writing WPF code to show a real-time plot which is a connected line containing about 10,000 points. It takes about 5 seconds to show a picture in my computer. Does anyone have an idea to make it quicker and within 0.5 second? class eee : FrameworkElement { public eee() { _children = new VisualCollection(this); Random rand = new Random(); DrawingVisual dv = new DrawingVisual(); using (DrawingContext dx = dv.RenderOpen()) { Pen drawingPen = new Pen(Brushes.Black, 1); double x=rand.Next(300); double y = rand.Next(300); for (double i = 0; i < 1000; i = i + 0.1) { y = 100 + rand.Next(100); dx