问题标签 [itemcontainergenerator]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
89 浏览

.net - Silverlight 搜索器

我正在尝试做类似于 Windows Phone 7 中的搜索器的事情,我所做的是以下内容,我有一个带有 TextChanged 事件的 TextBox 和一个 HyperlinkBut​​tons 列表框。我尝试的是这样的:

这是xaml:

这里的问题是当我有 68 个或更多元素时,ContainerFromItem 只返回 null ListBoxItems ...

任何的想法?

谢谢你们

0 投票
0 回答
108 浏览

wpf - 对于在非 ItemsControl 中实现虚拟化,是改进 ItemContainerGenerator 还是实现简单的自定义生成更好?

我们正在推出我们自己的特殊的基于 Items 的控件/面板组合,它不基于 ItemsControl 的子类(我们不能这样做的原因有很多,我不会在这里讨论)但我们的控件确实可以处理成千上万的数据项,所以我们想实现Visual虚拟化。

我们想知道的是,尝试将现有的 ItemContainerGenerator 类加入我们的设计或推出我们自己的虚拟化方法是否更有意义。

一方面,ItemContainerGenerator 已经处理了虚拟化并且非常高效,而且经过验证的代码几乎总是比从头开始更可取,但另一方面,ICG 是专门为使用而设计的,并且依赖于ItemsControl,同样,这个控件不是。另外,这是一个容器生成器,但在我们的例子中,我们只需要生成并布置一个特定的、已知的表示数据项的视觉效果。

现在,也许我过度简化了事情,但我所看到的只是需要确定哪些项目将在 ViewPort 中可见,确保创建、测量和排列这些项目的可视化表示,然后丢弃任何剩余的已经 -创造了视觉效果。为了跟踪这一切,似乎只需要一个简单的项目到可视化映射方案,可能需要在 DataItem 的 ViewModel 对象上使用 ItemVisual 附加属性。这样,当一个项目被移除/销毁时,我们只需检查是否存在现有的视觉效果,如果有,就对其进行核对。

也就是说,谁能想到我们不应该简单地推出自己的视觉虚拟化的原因?再一次,ICG 会这样做,但我想知道这是否将 Semi 带到商店获取鸡蛋。

0 投票
1 回答
1909 浏览

wpf - 如何强制 ItemContainerGenerator 为项目生成容器或启用 UI 虚拟化时如何将 TreeView 滚动到扩展节点?

TreeView 没有ScrollIntoView()方法
唯一的方法是调用TreeVewItem.BringIntoView()相应的数据项容器。
但是如果 node 不可见并且还没有生成容器,ItemsControl.ItemContainerGenerator.ContainerFromItem()将返回null.

所以应该有一些方法来强制 ItemContainerGenerator 为项目创建容器。

合理的问题是:如何扩展节点并保持不可见?!

简单的!IsExpanded绑定到 VM 的属性。UI 虚拟化按预期工作:
TreeViewItem.Expanded 的事件处理程序仅在手动滚动到项目时被调用。

0 投票
3 回答
7777 浏览

c# - ItemContainerGenerator.ContainerFromItem() 返回 null 而 VirtualizingStackPanel.IsVirtualizing="False"

我在这个问题上遇到了类似的问题,但VirtualizingStackPanel.IsVirtualizing="False"没有解决我的问题。有没有人面临同样的问题?

问题是我有一个自定义组合框,

但我无法通过内部获得对复选框的引用,

有什么建议吗?

我真正想要实现的是,

我想更改 checkboxes ischecked 属性,该属性取决于可以在运行时更改的其他对象。由于整个项目的当前状态,我目前无法更改,因此我无法使用绑定来做到这一点。所以基本上一旦创建了新的 MultiSelectionComboBox 我想做这样的事情,

0 投票
1 回答
219 浏览

c# - Where should you be instantiating UI controls from data objects when not an ItemsControl subclass?

TLDR version...

We're trying to create as basic Panel subclass with an observable Items property. The control then uses those data items to create one or more related child UI objects per data item.

Our first thought naturally was to simply subclass ItemsControl, but that doesn't seem to fit because it uses an ItemContainerGenerator which only generates one 'container' per item whereas again, we need to potentially create several (which aren't containers anyway.) Plus, all the created items have to be direct children on the panel, not held in a container which is why we can't go the route of data templates.

As such, I'm just using a standard Control and I'm trying to find the proper place/event where I should be instantiating/destroying the resulting child UI elements in response to changes in the Items collection.

Now the details...

First things first. If there was something like a ItemMultiContainerGenerator, that would be perfect, but I know of no such thing.

Ok, so simply monitor the collection for changes and put the UI generation in the CollectionChanged event! Right? That was our first guess too. The problem there is for every new 'Add' or 'Remove', we have to spin through all existing controls to 'defrag' certain indexing properties on them (think along the lines of a Grid.Row or ZIndex property) meaning if you add ten items, you run the defrag ten times, not once at the end.

Plus, that change event may come in on a different thread. If you attempted to dispatch to the main thread, your performance takes a nose-dive.

Our other attempt was to use MeasureOverride, since that was called only once in response to an InvalidateMeasure call, regardless of how many children we added or removed. The issues (there are many) with this approach is we lose context of whether something was added or removed, meaning we had to throw away all children and re-add back all new ones making this extremely inefficient. Plus, mucking around with the visual tree or setting bindings could cause the layout pass to execute multiple times since we were changing something that affects the layout, namingly the panels children.

What I'm trying to find is something that happens as part of the overall rendering process (i.e. from the time the control is told its invalid until it renders), but before the Measure/Layout passes are called. That way I can cache the adds/removes in the CollectionChanged event and simply mark the control as invalid, wait for this mystery event, then process the changes en mass, then send off the results to the layout engine and be done with it.

Using Reflector, I've tried to find out where the ItemsControl adds its children to the panel, but I didn't get too far considering the complexity of the control/ItemContainerGenerator pairing.

So where is the best place to create/add UI elements to a control based on data item changes?

0 投票
0 回答
85 浏览

xaml - 项目控制内的访问控制

这是我的itemsControl

我想访问前 3 个项目(即前 3 个堆栈面板)来更改它们的背景颜色,所以我ItemContainerGenerator 在下面尝试:

uiElement总是null有价值而我的 itemsControl 绑定好
有什么想法吗?或任何其他方式来获取特定项目itemsControl

0 投票
1 回答
505 浏览

windows-phone-8 - Alternative to ItemContainerGenerator with LongListSelector in WP8?

is there an alternative to ItemContainerGenerator when working with a grouped LongListSelector?

I have a context menu on every ListBoxItem. One option is "delete item". This works fine with the following code (not really neat, but it works; better ways to implement?):

I'd like to animate the item upon deletion. Therefore I need the FrameworkElement of that ListBoxItem. With a usual ListBox it works with

The Problem: LongListSelectors do not implement ItemContainerGenerator. How do I get the FrameworkElement for the animation?

Best Regards,

Marc

0 投票
1 回答
708 浏览

wpf - 为什么内容模板为空

我正在使用带有 MVVM 原则的 WPF。视图如下所示:

我会说没什么奇怪的。我正在尝试访问 myApp:TextBox 来设置焦点。为此,我在后面的代码中使用了这个(未完成)片段(我知道 MVVM 原则是什么,我不认为我违反了它们)。

您在事件处理程序中看到我的评论了吗?内容模板为空?为什么?做错了什么?

0 投票
0 回答
523 浏览

c# - DataGrid ItemContainerGenerator.ContainerFromIndex 的 Row 返回为 null 的原因

我打算继续关注 DataGrid 的选定行。为此,我搜索并找到链接如何将数据网格上的焦点设置到特定行?..当我在我的项目中尝试相同的操作时,我发现该行总是返回 null ..

我也为此进行了检查并获得了链接...在这里我没有使用虚拟化,而且我已经关闭了虚拟化..仍然面临同样的问题..我可以知道为什么返回null的一些原因吗?

0 投票
0 回答
131 浏览

wpf - 没有索引的 ItemContainerGenerator

我从 Panel 类创建了一个继承者,需要实现项目。我使用这段代码:

此方法使用 ItemSource 索引器生成项目。但我需要从对象生成项目。那就是我得到一个对象列表并需要生成项目。我怎样才能做到这一点?