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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:02:00+00:00 2026-05-21T02:02:00+00:00

I´m working on a Gui project for a company and we are trying to

  • 0

I´m working on a Gui project for a company and we are trying to create a navigational system using expanders and buttons.
The navagational pane is supposed to look something like this
Button
Expander
Button
Button
Expander
Button
Button
Button

The problem is that if i open expander it doesnt close if a push a button but it does close if i press another expander.

  • 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-05-21T02:02:01+00:00Added an answer on May 21, 2026 at 2:02 am

    Combinding multiple buttons and expanders together requires you to synchronize all the controls.
    You need the all buttons to close the open expander, and have the opening expander close the open expander.

    You can do this from the code-behind fairly easily by naming the controls; however, to implement this
    solution using MVVM (with binding) is a bit more tricky because the Expander IsExpanded property does not support two way binding.

    The key is to implement a Converter used by the Expander against its IsExpanded state as follows:

    IsExpanded="{Binding Path=IsButtonSelected, Converter={StaticResource expConv}}
    

    Each button command sets the IsButtonSelected flag to true which closes the open Expander.
    Because Expanders use a Converter you can use the ConvertBack method to close the open Expander from the opening Expander.

    I’ve include the code to help you follow along.

    Here is the View with 3 buttons and 2 Expanders:

    <Window x:Class="Expander.Views.MainView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:Helpers="clr-namespace:Expander.Converters" 
      Title="Main Window" 
      Height="400" Width="800">
      <Window.Resources>
        <Helpers:ExpanderConverter  x:Key="expConv"/>
      </Window.Resources>
      <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0" Grid.Column="0" Command="{Binding Path=ButtonSelected}" Content="Command 1"/>
        <Button Grid.Row="1" Grid.Column="0" Command="{Binding Path=ButtonSelected}" Content="Command 2"/>
        <Expander ExpandDirection="Down" 
                  Grid.Row="2" Grid.Column="0" 
                  IsExpanded="{Binding Path=IsButtonSelected, Converter={StaticResource expanderConv}}" 
                  Header="Details">
            <StackPanel Orientation="Horizontal">
            <Label Content="Name"/>
            <TextBox Width="100" />
            </StackPanel>
        </Expander>
        <Button Grid.Row="3" Grid.Column="0" Command="{Binding Path=ButtonSelected}" Content="Command 3"/>
        <Expander ExpandDirection="Down" 
                  Grid.Row="4" Grid.Column="0" 
                  IsExpanded="{Binding Path=IsButtonSelected, Converter={StaticResource expanderConv}}" 
                  Header="Details">
            <StackPanel Orientation="Horizontal">
                <Label Content="Address"/>
                <TextBox Width="100"/>
            </StackPanel>
        </Expander>
      </Grid>
    </Window>
    

    Here is the Converter called from the Expander:

    using System;
    using System.Globalization;
    using System.Windows.Data;
    
    namespace Expander.Converters
    {
      [ValueConversion(typeof(object), typeof(bool))]
      public sealed class ExpanderConverter : IValueConverter
      {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
          bool result = (bool)value;
          return !result;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
          bool result =(bool)value;
          return result;
        }
      }
    }
    

    Here is the ViewModel:
    I have not included the base class ViewModelBase and the Command code because you tagged MVVM so I’ll assume you have your own implementation for these.

    using System.Windows.Input;
    using Expander.Commands;
    
    namespace Expander.ViewModels
    {
      public class MainViewModel : ViewModelBase
      {
        public MainViewModel()
        {
          ButtonSelected = new DelegateCommand<object>(OnButtonSelected, CanButtonSelected);
        }
    
        public ICommand ButtonSelected { get; set; }
        private void OnButtonSelected(object obj)
        {
          IsButtonSelected = true;
        }
    
        private bool CanButtonSelected(object obj)
        {
          return true;
        } 
    
        private bool _isButtonSelected = true;
        public bool IsButtonSelected
        {
          get
          {
            return _isButtonSelected;
          }
          set
          {
            _isButtonSelected = value;
            OnPropertyChanged("IsButtonSelected");
          }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a C# project using System.Windows.Form to create the GUI, I have
I'm using Python's Tkinter to create a GUI for a project i'm working on.
I've recently begun working on a project regarding GUI building using some form of
I am working on a project where I need to write a GUI using
I'm relatively new to .NET GUI programming using WinForms (the project I'm working on
On the project I'm currently working on (a GUI for a testing system) I'm
I am currently working on a GUI software project for visualizing 3D scenes using
I'm working on a GUI for a card game and am using the ACM's
I was working on a simple GUI script yesterday using jdbc in eclipse. When
I am currently working on this big project (a GUI to control hardware) 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.