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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:29:23+00:00 2026-05-23T00:29:23+00:00

I have been banging my head on this one for hours and I am

  • 0

I have been banging my head on this one for hours and I am hoping someone can point me in the correct direction.

I have a button within my view which has a click event and a command attached. The click event sets the visibility of a grid row to collapsed or visible based upon the current state.

xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="120" />
        <RowDefinition x:Name="DetailHolder" Height="*" />
    </Grid.RowDefinitions>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="92.915" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Button x:Name="DetailButton"
                Grid.Column="1"
                Width="107"
                Height="23"
                Margin="196,94,0,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Click= "MoreDetail_Click"
                Command="{Binding GetCFSDetailCommand}"
                Content="View Details [+]" >
            <Button.DataContext>
                <mdc:SearchViewModel/>
            </Button.DataContext>
        </Button>
    </Grid>
    <Grid x:Name="MyDetail"
          Grid.Row="1"
          MinHeight="150"
          Visibility="Collapsed">
        <TextBlock Text="My Hidden Data" />
    </Grid>
</Grid>

The click command calls a method that tests the current visual state of the MyDetail section and expands or collapses it

The Command calls GetCFSDetailCommand from my viewModel etc

Where I am stuck is that I only want to call the Command GetCFSDetailCommand when the view is collapsed. The way it is set now is that command will fire every time the button is clicked. I can’t use ICommand CanExecute because I don’t want to disable the button. I’d appreciate any suggestions or ideas on how to go about achieving this. One thought was to test the visibility within the event code behind and then based upon that have the event call the Command. If this is the correct approach I would really appreciate a code sample as I have had no luck in calling the command from an event.

Thanks in advance

  • 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-23T00:29:24+00:00Added an answer on May 23, 2026 at 12:29 am

    Set your Command property in a DataTrigger

    <Button x:Name="DetailButton" Content="View Details [+]">
        <Button.Style>
            <Style TargetType="{x:Type Button}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=MyDetail, Path=Visibility}"
                                 Value="Collapsed">
                        <Setter Property="Command" Value="{Binding GetCFSDetailCommand}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    <Button>
    

    The Command will be set when the MyDetail panel is collapsed. Otherwise, it is unbound and nothing will happen.

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

Sidebar

Related Questions

I have been banging my head on this one for too long. I have
I have been banging my head on a wall with this one. I need
I've been banging my head against the wall with this one. I have a
I have been banging my head against this one for two days on and
I've been banging my head on this one for a while. Someone please resque
I've been banging my head against the wall with this one, may be someone
I've been banging my head on this one specific issue for about 2 hours
Ok, I have been banging my head on this one for a while, figure
I have been banging my head against the wall on this one, for some
I have been banging my head over this one for quite a while now

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.