Silverlight: disable user interface virtualization?

Is there an easy way to disable user interface virtualization in a ListBox control? I am trying to find a control in a ListBox control using the "FindName ()" method, but if the control is explicitly disconnected from the web browser window, it does not find the control. I'm pretty sure the culprit is UI virtualization. Since the control scrolls from the page, it is no longer retrieved using "FindName ()".

Second, I scroll it back to the screen, it returns the control successfully.

This is a continuation of this question:

Silverlight: FrameworkElement.FindName () does not find the control when it is not "visible" in the browser window

Update with sample code

This is the code I'm trying to get the control from. "DynamicTagFormFields" is a ListBox control.

textField tf = DynamicTagFormFields.FindName(s.KeyValue) as textField; 

This returns a valid textField if the actual textField control I am trying to retrieve is displayed to the end users on the screen. However, if I scroll the TextField control out of sight using the ListBox linear scrollbar, then run the process again, the above code will return null.

This is the XAML 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); 
+2
source share
2 answers

Have you tried this: -

 <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"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> 

The default panel is VirtualisingStackPanel , which may be causing your problem.

+8
source

at http://blogs.msdn.com/b/mcsuksoldev/archive/2010/04/13/performance-characteristics-of-the-silverlight-datagrid.aspx it says the following informative description of DataGrid virtualization, showing two ways, with with which you can disable it, the first of which is to add a ScrollViewer around the DataGrid, which is not really offered as a method to disable row virtualization, since the DataGrid has a title bar, so they also show how to change your XAML template. For a ListBox, although it does not have such a title, this may be a viable option for transferring it to ScrollViewer, giving it infinite size and thereby disabling row virtualization

... drop the ScrollViewer around your DataGrid. This gives the DataGrid infinite size and effectively disables virtualization. Unfortunately on my project, Id did this by accident, not realizing the effect on top of performance. You really need to use scrolling DataGrids bars, not ScrollViewer. Note that if you want to disable the Virtualization interface (for example, for small grids), you can re-create the DataGrid template and place the RowsPresenter inside the ScrollViewer, which again causes it to think that it has infinite size. This is useful because you are used to continuing to receive LoadRow and UnloadingRow events when scrolling. Be careful to do this correctly so that column headings scroll correctly (see the XAML in the appendix at the end of this article).

0
source

All Articles