如何为堆栈面板实现点击事件 [英] How to implement a click event for a stackpanel
问题描述
我在这里检查了 stackpanel 类 http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx 并且它没有点击事件.
I checked the stackpanel class here http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx and it has no click event.
我正在开发 Windows Phone 8 应用程序,我在堆栈面板上有一个文本框和一些按钮.我想包含一个功能,可以单击堆栈面板,然后将其上的控件的可见性设置为折叠状态,然后再次单击时它们变为可见.
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.
我该怎么做?
推荐答案
这个问题你可以用一个小技巧来解决,如果好就可以了,否则我再贴一个.
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;
}
}
这篇关于如何为堆栈面板实现点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!