Click here to Skip to main content
15,889,216 members
Home / Discussions / WPF
   

WPF

 
QuestionHow to read data from databinding controls(listbox in my code) [modified] Pin
Rocky2313-Apr-11 23:51
Rocky2313-Apr-11 23:51 
AnswerRe: How to read data from databinding controls(listbox in my code) Pin
Tarun.K.S14-Apr-11 0:07
Tarun.K.S14-Apr-11 0:07 
QuestionMoving multiple Shapes in Canvas Pin
Member 773700213-Apr-11 22:15
Member 773700213-Apr-11 22:15 
AnswerRe: Moving multiple Shapes in Canvas Pin
SledgeHammer0114-Apr-11 6:33
SledgeHammer0114-Apr-11 6:33 
GeneralRe: Moving multiple Shapes in Canvas Pin
Member 773700215-Apr-11 10:00
Member 773700215-Apr-11 10:00 
QuestionThe problem with listview and timer [modified] Pin
Tesic Goran13-Apr-11 19:33
professionalTesic Goran13-Apr-11 19:33 
QuestionWPF virtualizingstackpanel vs Grid or StackPanel Pin
devvvy13-Apr-11 18:52
devvvy13-Apr-11 18:52 
AnswerRe: WPF virtualizingstackpanel vs Grid or StackPanel [modified] Pin
Tarun.K.S13-Apr-11 21:18
Tarun.K.S13-Apr-11 21:18 
Actually VirtualizingStackPanel is mainly used to set the ItemsPanelTemplate for lets take an example for a ListBox where large data like 1000 or maybe 10,000 items or more have to be loaded into it.
You set it like this :

XML
<ListBox Name="myListBox">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation = "Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>


It means that you are setting the Panel for the ListBox so that "All" the items in ListBox can be arranged in a Vertical manner. Virtualization means that items will be created only when they are visible.
But if you substitute the VirtualizingStackPanel with a StackPanel, then performance will suffer heavily and your application will freeze for large amount of data.

If you think of normal circumstances like arranging two or three controls of your window like this :
XML
<StackPanel Orientation="Horizontal">
<TextBox Text="Hello"/>
<ComboBox Name="cmbItems"/>
</StackPanel>


Then there is no point in using a VirtualizingStackPanel here as there are only 2 controls and there will be no performance enhancement at all. You can replace the StackPanel with a Grid or Canvas too.

You can also think of setting the DataTemplate for the ListBox like this :

XML
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Item}"/>
<TextBlock Text="{Binding Path=AnotherItem}"/>
</DataTemplate>
</ListBox.ItemTemplate>


Again if you replace it with a VirtualizingStackPanel, it will not have any effect. You can as said above use Grid here too.
Its the ItemsPanelTemplate that you set matters.

So the point is for large amount of data, VirtualizingStackPanel is the correct choice and its by default used in ListBox, ListView and TreeView.
But using VirtualizingStackPanel also has some limitations. You cannot use Grouping and you have set the CanContentScroll of the ScrollViewer to True or else Virtualization will be switched off.
So it also depends on the requirement too. If you want to use Grouping, there is no point in using VirtualizingStackPanel.

Hope I was able to clear your doubt.

People with high attitude deserve the standing ovation of our highest finger!

My Blog![^]
modified on Friday, April 15, 2011 3:16 AM

GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
SledgeHammer0114-Apr-11 6:24
SledgeHammer0114-Apr-11 6:24 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S14-Apr-11 21:16
Tarun.K.S14-Apr-11 21:16 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Pete O'Hanlon14-Apr-11 22:47
mvePete O'Hanlon14-Apr-11 22:47 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S14-Apr-11 23:47
Tarun.K.S14-Apr-11 23:47 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Pete O'Hanlon15-Apr-11 0:03
mvePete O'Hanlon15-Apr-11 0:03 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S15-Apr-11 0:17
Tarun.K.S15-Apr-11 0:17 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
SledgeHammer0115-Apr-11 4:36
SledgeHammer0115-Apr-11 4:36 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S15-Apr-11 7:25
Tarun.K.S15-Apr-11 7:25 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
SledgeHammer0115-Apr-11 7:50
SledgeHammer0115-Apr-11 7:50 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S16-Apr-11 8:41
Tarun.K.S16-Apr-11 8:41 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
devvvy14-Apr-11 23:10
devvvy14-Apr-11 23:10 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
Tarun.K.S15-Apr-11 0:00
Tarun.K.S15-Apr-11 0:00 
AnswerRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
SledgeHammer0114-Apr-11 6:26
SledgeHammer0114-Apr-11 6:26 
GeneralRe: WPF virtualizingstackpanel vs Grid or StackPanel Pin
devvvy14-Apr-11 23:04
devvvy14-Apr-11 23:04 
QuestionHow to add the data from text box to already created list data item source Pin
Rocky2313-Apr-11 4:09
Rocky2313-Apr-11 4:09 
AnswerRe: How to add the data from text box to already created list data item source [modified] Pin
Tarun.K.S13-Apr-11 4:57
Tarun.K.S13-Apr-11 4:57 
GeneralRe: How to add the data from text box to already created list data item source Pin
Rocky2313-Apr-11 5:32
Rocky2313-Apr-11 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.