为什么我在Windows Phone 7 App中看不到按钮?

时间:2011-04-04 18:35:11

标签: windows-phone-7 silverlight-4.0

喜欢标题:)

我在教程中写道:http://msdn.microsoft.com/en-us/wp7trainingcourse_yourfirstwp7applab_topic3 做那样的事情。 我的代码:

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="120"/> <!-- Problem resolved -->
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

     <!-- this i can not see any ideas what is wrong? -->

    <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
        <Button x:Name = "SolveButton" Content="Solve" Margin="10"
                HorizontalAlignment="Center" Click="SolveButton_Click" />
        <StackPanel x:Name="StatusPanel" Orientation="Horizontal"
                    HorizontalAlignment="Center" Visibility="Collapsed">
            <TextBlock HorizontalAlignment="Center" Text="Your Moves: " TextWrapping="Wrap"
                   Foreground="#FFD0D0D0" FontSize="17.333"/>
            <TextBlock x:Name="TotalMovesTextBlock" HorizontalAlignment="Center" Text="N"
                   TextWrapping="Wrap" Foreground="#FFFFB000" FontSize="17.333"/>
        </StackPanel>
    </StackPanel>
    <!-- Here i can see anything under this comment -->
    <StackPanel Orientation="Vertical" VerticalAlignment="Top" Grid.Row="1">
        <Border x:Name="CongratsBorder" Height="30" Background="#FFF10DA2" 
                HorizontalAlignment="Center"
                Width="443" RenderTransformOrigin="0.5,0.5"
                UseLayoutRounding="False" Opacity="0">
            <Border.RenderTransform>
                <TransformGroup>
                    <ScaleTransform />
                    <SkewTransform />
                    <RotateTransform />
                    <TranslateTransform />
                </TransformGroup>
            </Border.RenderTransform>
            <TextBlock HorizontalAlignment="Center" Text="CONGRATULATIONS!" TextWrapping="Wrap"
                       Foreground="White" FontSize="17.333" VerticalAlignment="Center"
                       FontWeight="Bold"/>
        </Border>
        <Border x:Name="border" BorderThickness="3" Background="#FF262626" 
                HorizontalAlignment="Center" VerticalAlignment="Center" Padding="1" 
                RenderTransformOrigin="0.5,0.5">
            <Border.RenderTransform>
                <TransformGroup>
                    <ScaleTransform />
                    <SkewTransform />
                    <RotateTransform />
                    <TranslateTransform />
                </TransformGroup>
            </Border.RenderTransform>
            <Border.BorderBrush>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" >
                    <GradientStop Color="#FFF10DA2" Offset="0" />
                    <GradientStop Color="#FFEE7923" Offset="1" />
                </LinearGradientBrush>
            </Border.BorderBrush>
            <Canvas Height="435" Width="435">
                <Image x:Name="PreviewImage" Height="435" Width="435" Opacity="0.2" />
                <Canvas x:Name="GameContainer" Height="435" Width="435" />
            </Canvas>
        </Border>
        <TextBlock x:Name="TapToContinueTextBlock" HorizontalAlignment="Center" 
                   Text="Tap the picture to start the puzzle"
                   TextWrapping="Wrap" Foreground="#FFD0D0D0" FontSize="17.333" />
    </StackPanel>

    <!--TitlePanel contains the name of the application and page title-->
    <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>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
</Grid>

<!--Sample code showing usage of ApplicationBar-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
        <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
        <shell:ApplicationBar.MenuItems>
            <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
            <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
        </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->

2 个答案:

答案 0 :(得分:5)

你有一个网格

你在网格的第一行中有多个东西 - 所以它们被绘制在彼此之上。

  • 尝试将内容放入不同的网格行
  • 或者尝试用StackPanel替换最外面的Grid?

<RowDefinition Height="0.2"/>高度似乎也很小 - 尝试使用Height="Auto"

答案 1 :(得分:3)

您的第一个堆叠面板没有Grid.Row设置。它可能落后于第0行的TitlePanel。