29

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?

Steve B
  • 36,818
  • 21
  • 101
  • 174
user301016
  • 2,207
  • 7
  • 36
  • 50

2 Answers2

71

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.

Community
  • 1
  • 1
Bojan Resnik
  • 7,320
  • 28
  • 29
  • Thanks for the link. But this doesn't look like a collapsible panel in ASP.NET. Actually I am not using ASP.NET controls in my proj. But if I want that kind of control in WPF, how can this be acheived? Pls help me Thanks Ramm – user301016 Aug 20 '09 at 10:26
  • 3
    I am not sure what you mean - Expander *is* a WPF control and does seem to behave like a collapsible panel. Can you please explain what functionality you are missing? – Bojan Resnik Aug 20 '09 at 11:36
10

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 ...

user2821937
  • 119
  • 2
  • 3