WP7隐藏文本框的方法
我想要三个文本框(仅显示其中一个用于输入文本)要输入文本的文本框由按钮选择 我将文本框的不透明度属性设置为 0.0 以隐藏,将不透明度设置为 1.0 以显示。
在xaml页面中:
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button x:Name="btnGood" HorizontalAlignment="Center"
Content="Good"
Click="Toggle_Click">
</Button>
<Button x:Name="btnBad" HorizontalAlignment="Center"
Content="Bad"
Click="Toggle_Click">
</Button>
<Button x:Name="btnDetail" HorizontalAlignment="Center"
Content="Detail"
Click="Toggle_Click">
</Button>
</StackPanel>
<Grid Grid.Row="1">
<TextBox x:Name="txtDetail" AcceptsReturn="True"
TextWrapping="Wrap" />
<TextBox x:Name="txtBad" AcceptsReturn="True"
TextWrapping="Wrap" Opacity="0.0"/>
<TextBox x:Name="txtGood" AcceptsReturn="True"
TextWrapping="Wrap" Opacity="0.0"/>
</Grid>
在代码中:
private void Toggle_Click(object sender, RoutedEventArgs e)
{
Button btnSender = (Button)sender;
string id = btnSender.Content.ToString();
switch (id)
{
case "Good":
{
txtDetail.Opacity = 0.0;
txtBad.Opacity = 0.0;
txtGood.Opacity = 1.0;
}
break;
case "Bad":
{
txtDetail.Opacity = 0.0;
txtGood.Opacity = 0.0;
txtBad.Opacity = 1.0;
}
break;
case "Detail":
{
txtBad.Opacity = 0.0;
txtGood.Opacity = 0.0;
txtDetail.Opacity = 1.0;
}
break;
default:
break;
}
}
问题是:当单击good按钮时,会显示txtGood文本框,并且可以看到键入的字符。 但是,当单击“坏”或“详细信息”按钮时,文本将输入到 txtGood 中,并且不会显示,仅显示暗色的空文本框。但它应该输入到相应的文本框中,并且应该对用户可见。如何解决这个问题?
I want to have three textboxes(only one of them will be shown to input text) textbox to be enter text is chosen by buttons
I set opacity property of textbox 0.0 to hide set opacity to 1.0 to show.
In xaml page:
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button x:Name="btnGood" HorizontalAlignment="Center"
Content="Good"
Click="Toggle_Click">
</Button>
<Button x:Name="btnBad" HorizontalAlignment="Center"
Content="Bad"
Click="Toggle_Click">
</Button>
<Button x:Name="btnDetail" HorizontalAlignment="Center"
Content="Detail"
Click="Toggle_Click">
</Button>
</StackPanel>
<Grid Grid.Row="1">
<TextBox x:Name="txtDetail" AcceptsReturn="True"
TextWrapping="Wrap" />
<TextBox x:Name="txtBad" AcceptsReturn="True"
TextWrapping="Wrap" Opacity="0.0"/>
<TextBox x:Name="txtGood" AcceptsReturn="True"
TextWrapping="Wrap" Opacity="0.0"/>
</Grid>
In Code:
private void Toggle_Click(object sender, RoutedEventArgs e)
{
Button btnSender = (Button)sender;
string id = btnSender.Content.ToString();
switch (id)
{
case "Good":
{
txtDetail.Opacity = 0.0;
txtBad.Opacity = 0.0;
txtGood.Opacity = 1.0;
}
break;
case "Bad":
{
txtDetail.Opacity = 0.0;
txtGood.Opacity = 0.0;
txtBad.Opacity = 1.0;
}
break;
case "Detail":
{
txtBad.Opacity = 0.0;
txtGood.Opacity = 0.0;
txtDetail.Opacity = 1.0;
}
break;
default:
break;
}
}
The Problem is: when good button is clicked txtGood textbox is shown and can see typed characters.
But when either bad or detail button is clicked the texts are entered into txtGood and it is not shown a dull colored empty textbox only shown. But it should be entered into respective textboxes and it should be visible to user. How can be fixed this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用 txtBad.Visibility = Visibility.Collapsed?这是隐藏屏幕上某些内容的更好方法。
Why don't you use
txtBad.Visibility = Visibility.Collapsed
? It's a better way to hide some content on a screen.可见性出了什么问题?为什么要使用不透明度?
What's wrong with Visibility? Why are you using Opacity?