2016-10-10 36 views
0

我試圖做一個記憶遊戲,如下所示代碼:我沒有看到我添加圖像 - UWP

<Page 
x:Class="MemoGame.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:MemoGame" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="1*"/> 
     <ColumnDefinition Width="1*"/> 
     <ColumnDefinition Width="1*"/> 
     <ColumnDefinition Width="1*"/> 
    </Grid.ColumnDefinitions> 

    <Grid.RowDefinitions> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="2*"/> 
    </Grid.RowDefinitions> 


    <TextBlock Grid.Row="0" Grid.ColumnSpan="4" FontSize="24" FontStyle="Italic">Memo game by Ido and Jacob</TextBlock> 

    <Rectangle x:Name="R1C1" Grid.Row="1" Grid.Column="0" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R1C2" Grid.Row="1" Grid.Column="1" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R1C3" Grid.Row="1" Grid.Column="2" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R1C4" Grid.Row="1" Grid.Column="3" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 

    <Rectangle x:Name="R2C1" Grid.Row="2" Grid.Column="0" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R2C2" Grid.Row="2" Grid.Column="1" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R2C3" Grid.Row="2" Grid.Column="2" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R2C4" Grid.Row="2" Grid.Column="3" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 

    <Rectangle x:Name="R3C1" Grid.Row="3" Grid.Column="0" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R3C2" Grid.Row="3" Grid.Column="1" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R3C3" Grid.Row="3" Grid.Column="2" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R3C4" Grid.Row="3" Grid.Column="3" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 

    <Rectangle x:Name="R4C1" Grid.Row="4" Grid.Column="0" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R4C2" Grid.Row="4" Grid.Column="1" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R4C3" Grid.Row="4" Grid.Column="2" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
    <Rectangle x:Name="R4C4" Grid.Row="4" Grid.Column="3" Fill="Gray" StrokeThickness="2" Margin="4" Stroke="Black"></Rectangle> 
</Grid> 

然而,當我添加圖像,我看不到它。我設置的圖像如下:

 <Image Source="c:\users\prinsnal\documents\visual studio 2015\Projects\MemoGame\MemoGame\Assets\I3LeJ3H.png" Grid.Row="0" Grid.Column="0"></Image> 

沒有顯示時,畫面存在,我拖着它的資產,我應該怎樣做才能夠看到的景象?我應該在同一個面板上放置圖片和文本塊或按鈕嗎?

+0

你有一個看看[Image.Source](https://msdn.microsoft.com/library/windows/apps/xaml/windows.ui.xaml.controls.image.source.aspx)頁面中的例子? –

回答

0

試試這個:

<Image Source="Assets\I3LeJ3H.png" Grid.Row="0" Grid.Column="0"></Image> 

圖像必須在Visual Studio中添加的資產目錄。如果不是:

  1. 右鍵單擊資產目錄在Visual Studio
  2. 添加
  3. 已存在元素
  4. 選擇圖像

It works for me