Pages

Tuesday 12 March 2013

Expander Control in WPF

Expander Control in WPF

StackPanel is with expanding panels—when the panels expand or contract, everything else changes size automatically. The WPF team hasbeen nice enough to provide an expanding/contracting control which makes this behavior easy to demonstrate.The Expander control works similarly to the sections in Windows Explorer that allow you to show or hide different sections




Code For this is given below-

<ScrollViewer VerticalScrollBarVisibility="Auto">
            <StackPanel Orientation="Vertical">
                <Expander Header="My Documents" BorderThickness="3" BorderBrush="Aquamarine" 
 Background="Chocolate">
                    <StackPanel Background="Aqua" >
                        <Label >Books</Label>
                        <Label>Data</Label>
                        <Label>Personal</Label>
                        <Label>Movies</Label>
                        <Label>Songs</Label>
                    </StackPanel>
                </Expander>
                <Expander Header="My Computers"  BorderThickness="3" BorderBrush="AntiqueWhite" 
 Background="Chocolate">
                    <StackPanel>
                        <Button>Local Disk C:</Button>
                        <Button>Local Disk D:</Button>
                        <Button>Local Disk E:</Button>
                        <Button>Local Disk F:</Button>
                        <Button>Local Disk G:</Button>
                        <Button>Local Disk H:</Button>
                    </StackPanel>
                </Expander>
            </StackPanel>
        </ScrollViewer> 
 
The Expander can only contain one thing: its contents. If we want to add multiple items, we have to put something inside the Expander that can hold some number of other things. The StackPanel, as with all the other layout panels, can hold multiple items, so we can add another StackPanel.

The StackPanel itself solves some specific layout scenarios, but it’s quite flexible. It could be used, for example, to build a calculator. You should be able to see how this would work—one vertical StackPanel containing a number of vertical StackPanels for the buttons. It wouldn’t be easy, but it would be possible. In the next section, we will talk about the DockPanel. The DockPanel can be used to solve some of the same problems but in a different way. As with the StackPanel, the DockPanel, while flexible, is designed to handle a different set of scenarios.
 

No comments:

Post a Comment