virtualizing Stackpanel

hi here i'm trying to display some buttons in a stack panel horizontally an dit exceeds the screen visible area what i want is, to display what are the items are currently displayed now on the screen in ta text box. How can i do this (for this i'm using virtualizingStackPanel but i dont know how to use it exactly)

This is my code

<ListBox Name="lbox" Height ="80" virtualizingStackPanel.IsVirtualizing ="True">

<ListBoxItem Name="lbitem" HorizontalAlignment="Center">

<StackPanel width="Auto" Orientation ="Horizontal" Name="lbStackpanel" HorizontalAlignment="Center" Background="Black" virtualizingStackPanel.IsVirtualizing ="True"virtualizingStackPanel.IsVirtualizing ="True">

<Button>Button1</Button>

<Button>Button2</Button>

<Button>Button3</Button>

<Button>Button4</Button>

<Button>Button5</Button>

<Button>Button6</Button>

<Button>Button7</Button>

<Button>Button8</Button>

<Button>Button9</Button>

<Button>Button10</Button>

<Button>Button11</Button>

<Button>Button12</Button>

<Button>Button13</Button>

<Button>Button14</Button>

<Button>Button15</Button>

<Button>Button16</Button>

<Button>Button17</Button>

<Button>Button18</Button>

<Button>Button19</Button>

<Button>Button20</Button>

</StackPanel>

</ListBoxItem>

</ListBox>

Thanx-Nagu

[1861 byte] By [Nagu] at [2008-2-15]
# 1

Before I start, this thread really belongs in the WPF forums, rather than the C# ones, since this is a WPF question.

Anyway, the documentation for VirtualizingStackPanel contains an important note:

"Virtualization in a StackPanel only happens when items are data-bound."

You're not doing data binding here, so what you're trying simply isn't going to work.

The idea behind a virtualizing stack panel is that it only creates UI elements for those items that are currently visible. But you've gone ahead and created 20 UI elements (buttons in this case). So there's nothing the virtualizing stack panel can do here - it can't defer creation of elements that you've already gone ahead and created!

Virtualization only really makes sense in the context of data-driven item generation. The classic example is that your application has a big list of data items (e.g. DataRows in a DataTable), but only a fraction of these have any visual representation at any one time. Data binding is able to generate UI elements based on source data (through a combination of the ItemsControl's container generation, and data binding's template instantiation). Virtualization takes that concept and refines it so that element generation is done on demand.

You're not doing element generation here - you're just creating a bunch of elements up front. Since you're not using element generation, you can't use virtualization.

IanG at 2007-9-10 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...