Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a collapsible panel in WPF

I am creating a Windows application (WPF) and C#. In my view, I have to add few layouts like browsing a folder, displaying the files in the folder in a list view...etc

My requirement is : The panels mentioned above should be collapsible panels, I guess, we dont have option of collapsible panel in wpf.

I have to create a custom control for this? If so, Please suggest me how to do this?

like image 511
user301016 Avatar asked Aug 20 '09 09:08

user301016


2 Answers

The Expander control may be what you are looking for. From MSDN:

Expander Class

Represents the control that displays a header that has a collapsible window that displays content.

like image 75
Bojan Resnik Avatar answered Sep 21 '22 10:09

Bojan Resnik


May like this?

 <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>
    <Border  Background="Red" Height="12" VerticalAlignment="Top" MouseEnter="StackPanel_MouseEnter" MouseLeave="StackPanel_MouseLeave"></Border>
</Grid>    

C# code behind

 private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
    {
        Border sp = sender as Border;
        DoubleAnimation db = new DoubleAnimation();
        //db.From = 12;
        db.To = 150;
        db.Duration = TimeSpan.FromSeconds(0.5);
        db.AutoReverse = false;
        db.RepeatBehavior = new RepeatBehavior(1);
        sp.BeginAnimation(StackPanel.HeightProperty, db);
    }

    private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
    {
        Border sp = sender as Border;
        DoubleAnimation db = new DoubleAnimation();
        //db.From = 12;
        db.To = 12;
        db.Duration = TimeSpan.FromSeconds(0.5);
        db.AutoReverse = false;
        db.RepeatBehavior = new RepeatBehavior(1);
        sp.BeginAnimation(StackPanel.HeightProperty, db);
    }
}

You can use any element control like grid, stack, dock, border ...

like image 43
user2821937 Avatar answered Sep 23 '22 10:09

user2821937