WP7隐藏文本框的方法

发布于 2025-01-07 17:53:47 字数 2302 浏览 1 评论 0原文

我想要三个文本框(仅显示其中一个用于输入文本)要输入文本的文本框由按钮选择 我将文本框的不透明度属性设置为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

短暂陪伴 2025-01-14 17:53:47

为什么不使用 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.

谁对谁错谁最难过 2025-01-14 17:53:47

可见性出了什么问题?为什么要使用不透明度?

What's wrong with Visibility? Why are you using Opacity?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文