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 8587357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:33:02+00:00 2026-06-11T22:33:02+00:00

I am trying to create a WPF window to have a simple expander to

  • 0

I am trying to create a WPF window to have a simple expander to extend the datagrid when the user clicks on the More expander button. When the user wants to hide the datagrid, user just has to clik on the Less expander button.

I am also using dock panel to separate header, left, right and footer.

The problems are :

  1. I want to have the less button to be in center before the user
    click on the more expander button. When the user clicks on the more
    expander button, the less button will be pushed to the left, to show
    the datagrid on the right.
  2. How do I change the name of the expander when its closed and
    open. Can I do it at the xaml level?

Below is the xaml code:

<Window x:Class="M.SalesWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SalesWindow" Height="300" Width="300">
    <DockPanel>

        <StackPanel DockPanel.Dock="Top">
            <Label FontSize="28" Content="Sales">
            </Label>
        </StackPanel>

        <StackPanel DockPanel.Dock="Left" Width="auto" HorizontalAlignment="Center">
            <Label FontSize="15" Content="Enter Amount" Height="26" Width="168" />
            <Separator Width="168" />
        </StackPanel>

        <StackPanel DockPanel.Dock="Right">
            <Expander ExpandDirection="Left" HorizontalAlignment="Right" VerticalAlignment="Stretch">
                <Expander.Header>
                    <TextBlock Text="More">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="-90"/>
                    </TextBlock.LayoutTransform>
                    </TextBlock>
                </Expander.Header>
                <Expander.Content>
                    <StackPanel>
                        <DataGrid ItemsSource="{Binding Products}">

                        </DataGrid>
                    </StackPanel>
                </Expander.Content>
            </Expander>
        </StackPanel>

    </DockPanel>
</Window>

Thank you.

  • 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-11T22:33:03+00:00Added an answer on June 11, 2026 at 10:33 pm

    Replace your code with the below code and see the magic. This will also solve your problem of alignment as per your requirement. I have removed the DockPanel as you can achieve the similar result with this piece of code.

    <StackPanel>
        <StackPanel>
            <Label FontSize="28" Content="Sales">
            </Label>
        </StackPanel>
    
        <Grid>
            <Grid.ColumnDefinitions>                
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" HorizontalAlignment="Center">
                <Label FontSize="15" Content="Enter Amount" Height="26" Width="168" />
                <Separator Width="168" />
            </StackPanel>
    
             <Expander Grid.Column="1" ExpandDirection="Left" HorizontalAlignment="Right" VerticalAlignment="Stretch">
                <Expander.Style>
                    <Style TargetType="Expander">
                        <Setter Property="IsExpanded" Value="False" />
                        <Setter Property="Header">
                            <Setter.Value>
                                <TextBlock Text="Less">
                                    <TextBlock.LayoutTransform>
                                        <RotateTransform Angle="-90"/>
                                    </TextBlock.LayoutTransform>
                                </TextBlock>
                            </Setter.Value>
                        </Setter>
    
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsExpanded,RelativeSource={RelativeSource Self}}" Value="True">
                                <Setter Property="Header">
                                    <Setter.Value>
                                        <TextBlock Text="More">
                                            <TextBlock.LayoutTransform>
                                                <RotateTransform Angle="-90"/>
                                            </TextBlock.LayoutTransform>
                                        </TextBlock>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Expander.Style>
                <Expander.Content>
                    <StackPanel>
                        <DataGrid ItemsSource="{Binding Products}">
    
                        </DataGrid>
                    </StackPanel>
                </Expander.Content>
            </Expander>
    
        </Grid>
    </StackPanel>
    

    The trick lies under the following lines of code.

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a child window in WPF.this child window should open
I'm trying to create a user control in WPF to represent a Go board
I'm trying to create a pretty simple WPF interface, and from what I know
I'm trying to create a simple toolbar in WPF, but the toolbar shows up
I have created a wpf vb.net project and am trying to set a simple
I have a WPF application where I'm trying to create a diagnostics panel that's
I am trying to create a user control within a WPF application that will
I am trying to create a custom user control in WPF. I want to
I'm new to WPF/C#, and I'm trying to create a simple sql query application
I am trying to use WPF printing from PowerShell. I have found a simple

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.