Siva Sankaran
Siva Sankaran

Reputation: 1566

how to hide a textbox in WP7

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 ?

Upvotes: 0

Views: 2180

Answers (2)

MarcinJuraszek
MarcinJuraszek

Reputation: 125660

Why don't you use txtBad.Visibility = Visibility.Collapsed? It's a better way to hide some content on a screen.

Upvotes: 3

Michael Sync
Michael Sync

Reputation: 5014

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

Upvotes: 2

Related Questions