Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:17:39+00:00 2026-06-05T00:17:39+00:00

I have created a nested WPF Datagrid. I see you can expand it by

  • 0

I have created a nested WPF Datagrid. I see you can expand it by clicking on the row, but it doesn’t collapse when you do the same thing.

Few questions:

  1. How can the user collapse the grid?
  2. Is there a way to get Expand/Collapse buttons on the parent rows?
  3. Whenever you click on a different parent to expand, it collapses the previous one you are on. Is there a way to get the grid to stay the way you make it. i.e. If I expand row 1 then go to row 3, row 1 will stay where I expanded it to.

Thanks,
Greg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:17:40+00:00Added an answer on June 5, 2026 at 12:17 am

    There are couple approaches to reach such behavior.
    For example
    Expand/Collapse button in a Silverlight DataGrid.

    If you prefer xaml then use:

    <Style x:Key="ExpandableDataGridRowHeaderStyle"
               TargetType="sdk:DataGridRowHeader">
        <Setter Property="Background"
                    Value="#99E9EEF4" />
        <Setter Property="IsTabStop"
                    Value="False" />
        <Setter Property="SeparatorBrush"
                    Value="#FFFFFFFF" />
        <Setter Property="SeparatorVisibility"
                    Value="Collapsed" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdk:DataGridRowHeader">
                    <Grid x:Name="Root">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="25" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>                           
                        <Border BorderBrush="#FFFFFFFF"
                                    BorderThickness="1,0,1,0"
                                    Grid.ColumnSpan="2"
                                    Grid.RowSpan="3">
                            <Grid>
                                <Rectangle x:Name="RowInvalidVisualElement"
                                               Grid.ColumnSpan="2"
                                               Fill="#FFF7D8DB"
                                               Opacity="0"
                                               Grid.RowSpan="3"
                                               Stretch="Fill" />
                                <Rectangle x:Name="BackgroundRectangle"
                                               Grid.ColumnSpan="2"
                                               Fill="Transparent"
                                               Grid.RowSpan="3"
                                               Stretch="Fill" />
                            </Grid>
                        </Border>
                        <Button Background="{x:Null}"
                                    BorderBrush="{x:Null}"
                                    BorderThickness="0"
                                    Padding="0"
                                    Grid.RowSpan="1"
                                    HorizontalAlignment="Stretch">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <AttachedBehaviors:ExpandButtonAction/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    And AttachedBehavior that actually will change DetailsVisibility:

    public class ExpandButtonAction : TargetedTriggerAction<FrameworkElement>
    {
        #region Invoke
    
        protected override void Invoke(object parameter)
        {
            RoutedEventArgs eventArgs = (RoutedEventArgs) parameter;
            Button bsender = eventArgs.OriginalSource as Button;
            var row = DataGridRow.GetRowContainingElement(eventArgs.OriginalSource as FrameworkElement);
            if (row.DetailsVisibility == Visibility.Visible)
            {
                row.DetailsVisibility = Visibility.Collapsed;
            }
            else
            {
                row.DetailsVisibility = Visibility.Visible;
            }
        }
    
        #endregion
    }
    

    And apply this for RowHeaderStyle of DataGrid where you want to expand/collapse DetailsTemplate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a very simple nested loop example and am struggling to write
I have a WPF UserControl nested inside an ElementHost in a WinForm UserControl intended
I have created a customer c# DropDownList control that can render out it's contents
So I have created a nested template (a map of vectors) using stanford's CS106
I have created a Server, Client kind of program with RMI. But whenever I
I created a nested array as I could so far but I feel like
I have created a nested list with drag/drop functionality. My issue is that I
I have created nested cursor which basically compares column values of one table To
I have created a symbolic link to a deeply nested directory. Using symbolic link
I have a List object, with nested Tasks. I have created a page that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.