简体   繁体   中英

howto add a textBlock to a silverlight/XNA WP7 app?

hi i have a question about the silverlight/xna template for wp7 programming.

i start a new projekt and then draw some content in the game screen. and then i add the following to the xaml page of GamePage:

<Grid Height="800" Name="grid1" Width="480" Background="White">
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBlock1" Text="Lifes: 3" VerticalAlignment="Top" Foreground="Black" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="393,12,0,0" Name="textBlock2" Text="Points: 0" VerticalAlignment="Top" Foreground="Black" />
</Grid>

but the problem is i dont see the textBlock and i dont know why. who can give me a hint?

Does your code look anything like this?

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <Grid Height="800" Name="grid1" Grid.Row="1" Width="480" Background="White">
        <TextBlock Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBlock1" Text="Lifes: 3" VerticalAlignment="Top" Foreground="Black" />
        <TextBlock Height="30" HorizontalAlignment="Left" Margin="367,12,0,0" Name="textBlock2" Text="Points: 0" VerticalAlignment="Top" Foreground="Black" />
    </Grid>
</Grid>

Because I tested this and it works fine. Here's the result:

Update:

Otherwise you should provide some other code which might cause the problem.

TIP: There was a typo in initial question text. @gurehbgui asked why he isn't seeing the textBox (when he meant TextBlock). That is the reason why this answer is here. After the typo has been fixed this answer became no longer relevant.

You are using a TextBlock control.

You should use TextBox to have an edit field for a text element.

Also, since the Foreground is set to Black, a control may not be visible on a black background. You can use Silverlight Spy application to inspect the WP7 GUI layout and debug such problems. Spy supports trial period.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM