Silverlight:禁用 UI 虚拟化?
有没有一种简单的方法可以禁用 ListBox 控件上的 UI 虚拟化? 我尝试使用“FindName()”方法在 ListBox 控件中查找控件,但如果该控件明显位于 Web 浏览器窗口之外,则无法找到该控件。我几乎可以肯定罪魁祸首是 UI 虚拟化。 当控件滚动离开页面时,它不再通过“FindName()”成功检索。
当我将其滚动回到屏幕上时,它成功返回控制。
这是这个问题的扩展:
Silverlight: FrameworkElement.FindName() 在浏览器窗口中不“可见”时找不到控件
使用编码示例更新
这是我尝试检索控件的背后代码。 “DynamicTagFormFields”是ListBox 控件。
textField tf = DynamicTagFormFields.FindName(s.KeyValue) as textField;
如果最终用户可以在屏幕上查看我尝试检索的实际 textField 控件,则这将返回有效的“textField”对象。 但是,如果我使用 ListBox 的垂直滚动条将 textField 控件滚动到视图之外,然后再次强制该过程,则上述代码将返回 null。
这是 ListBox 的 XAML:
<ListBox x:Name="DynamicTagFormFields" Margin="0" Style="{StaticResource ListBoxStyle1}" ItemContainerStyle="{StaticResource ListBoxItemStyle4}" d:LayoutOverrides="Height" Grid.Row="2" IsTabStop="False" TabNavigation="Local" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
使用以下代码以编程方式将 textField 对象动态添加到 ListBox:
DynamicTagFormFields.Items.Add(textFieldControl);
Is there a simple way to disable UI virtualization on a ListBox control?
I'm attempting to find a control within a ListBox control using the "FindName()" method, but in the case that the control is visibly off of the Web Browser window, it's not finding the control. I'm almost certain the culprit is UI virtualization.
As the control is scrolled off the page, it is no longer retrieved successfully via "FindName()".
The second I scroll it back onto the screen, it returns the control successfully.
This is an extension of this question:
Update with coding example
This is the code behind where I attempt to retrieve the control.
"DynamicTagFormFields" is the ListBox control.
textField tf = DynamicTagFormFields.FindName(s.KeyValue) as textField;
This returns a valid "textField" object if the actual textField control that I'm attempting to retrieve is viewable on the screen to the end user.
However, if I scroll the textField control out of view using the ListBox's vertical scroll bar, then force the process again, the aforementioned code will return null.
This is the XAML of the ListBox:
<ListBox x:Name="DynamicTagFormFields" Margin="0" Style="{StaticResource ListBoxStyle1}" ItemContainerStyle="{StaticResource ListBoxItemStyle4}" d:LayoutOverrides="Height" Grid.Row="2" IsTabStop="False" TabNavigation="Local" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
The textField object is dynamically added to the ListBox programmatically with the following code:
DynamicTagFormFields.Items.Add(textFieldControl);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过此操作:-
默认面板是 VirtualisingStackPanel,这可能是导致您的问题的原因。
Have you tried this:-
The default panel is the
VirtualisingStackPanel
which may be the cause of your problem.在
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/04/13/performance-characteristics-of-the-silverlight-datagrid.aspx
它说了以下有关 DataGrid 虚拟化的信息,显示了两种关闭它的方法,第一种是在 DataGrid 周围添加 ScrollViewer,实际上并不建议将其作为关闭行虚拟化的方法,因为 DataGrid 有标题行,因此它们还展示了如何更改其 XAML 模板。对于 ListBox,虽然没有这样的标头,但将其包装在 ScrollViewer 中可能是一个可行的选择,给它无限的大小,从而关闭行虚拟化
at
http://blogs.msdn.com/b/mcsuksoldev/archive/2010/04/13/performance-characteristics-of-the-silverlight-datagrid.aspx
it says the following informative stuff regarding the DataGrid's virtualization, showing two ways that you can switch it off, the first one being to add a ScrollViewer around the DataGrid which is not in fact suggested as a method to turn off row virtualization, since DataGrid has a header row, so they also show how to change its XAML template. For ListBox though that doesn't have such header, it could be a viable option to wrap it in a ScrollViewer, giving it infinite size and thus turning off the row virtualization