Friday, January 28, 2011

WPF Interview Questions ,How can I make ListBox arrange its items horizontally instead of vertically?



One way is to define a new control template, but all ItemsControls provide a shortcut with its ItemsPanel property. ItemsPanel enables you to swap out the panel used to arrange items while leaving everything else about the control intact. ListBox uses a panel called VirtualizingStackPanel to arrange its items vertically, but the following code replaces it with a new VirtualizingStackPanel that explicitly sets its Orientation to Horizontal:

The translation of this XAML to procedural code is not straightforward, but here’s how you

can accomplish the same task in C#:

FrameworkElementFactory panelFactory =

new FrameworkElementFactory(typeof(VirtualizingStackPanel));

panelFactory.SetValue(VirtualizingStackPanel.OrientationProperty,

Orientation.Horizontal);

myListBox.ItemsPanel = new ItemsPanelTemplate(panelFactory);

No comments:

Post a Comment

Thermal conductivity calculations, experiments, molecular simulations

Nowadays various experimental procedures are there to calculate the thermal conductivity of various materials using various techniques. Th...

About Me

COTACT: studymaterialforall@gmail.com