Search code examples
c#windows-phone-8visibilitystackpanel

How to implement a click event for a stackpanel


I checked the stackpanel class here http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx and it has no click event.

I'm working on a windows phone 8 app and I've got a textbox and some buttons on a stack panel. I want to include a feature where the stackpanel can be clicked then the visibility of the controls on it are set to collapsed, and then when clicked again they become visible.

How do I do this?


Solution

  • You can solve this problem in a little tricky manner, if it is good then it's ok otherwise i'll Post the another one.

     <StackPanel Background="Red" MinHeight="80"  VerticalAlignment="Top" Tap="StackPanel_Tap_1" Orientation="Horizontal">
                <Button x:Name="btn1" Content="Button"/>
                <Button x:Name="btn2" Content="Button"/>
                <TextBox Height="72" x:Name="textbox1" TextWrapping="Wrap" Text="TextBox" Width="456"/>
            </StackPanel> 
    
    
    
    
     private void StackPanel_Tap_1(object sender, GestureEventArgs e)
        {
    
    
            if (btn1.IsEnabled==false)
            {
                btn1.IsEnabled = true;
                btn1.Visibility = Visibility.Visible;
                btn2.Visibility = Visibility.Visible;
                textbox1.Visibility = Visibility.Visible;
            }
            else
            {
    
                btn1.IsEnabled = false;
                btn1.Visibility = Visibility.Collapsed;
                btn2.Visibility = Visibility.Collapsed;
                textbox1.Visibility = Visibility.Collapsed;
            }
    
        }