Question

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?

Was it helpful?

Solution 4

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;
        }

    }

OTHER TIPS

Try using the MouseLeftButtonUp event.

You could just wrap the whole stackpanel in a button:

<button>
    <stackpanel>
    </stackpanel>
</button>

Then attach a click event or command to the button as you see fit.

put the StackPanel inside the Border control, use MouseLeftButtonUp of the Border to handle event and set background of the Border to #000001

You could probably use the TouchUp and TouchDown event. But I think you have to check if the TouchDown is on the same StackPanel as the TouchUp. So you can check if it was a "click".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top