我想在我的应用中为我的某个页面添加图片。我正在使用Visual Studio 2010并在VB.NET中编码,并且首先添加图像我将图像控件插入到页面上,然后我选择要插入的图像的源,然后设置图像构建操作to'content'并构建程序,但图像看起来不可见?
有人知道为什么会这样做吗?
我的XML代码如下:
<phone:PhoneApplicationPage
x:Class="RSG_Engineer.MainPage"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" OpacityMask="{x:Null}">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Height="133" HorizontalAlignment="Left" Name="Rectangle1" Stroke="Black" StrokeThickness="0" VerticalAlignment="Top" Width="480" Fill="#FF00B1FF" />
<!--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="RSG Engineer" Style="{StaticResource PhoneTextNormalStyle}" Foreground="White" />
<TextBlock x:Name="PageTitle" Text="Main menu" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Foreground="White" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Background="White">
<TextBox Height="78" HorizontalAlignment="Left" Margin="18,16,0,0" Name="TextBox1" Text="Please select one of the following:" VerticalAlignment="Top" Width="460" Background="{x:Null}" Foreground="#FF00B1FF" BorderBrush="{x:Null}" />
<Button Content="Hex Date" Height="72" HorizontalAlignment="Left" Margin="81,88,0,0" Name="btnHex" VerticalAlignment="Top" Width="275" Foreground="#FF00B1FF" BorderBrush="#FF00B1FF" />
<Button Content="Julian Date" Height="72" HorizontalAlignment="Left" Margin="81,196,0,0" Name="btnJulian" VerticalAlignment="Top" Width="275" BorderBrush="#FF00B1FF" Foreground="#FF00B1FF" />
<Button Content="Reverse Julian Date" Height="72" HorizontalAlignment="Left" Margin="81,304,0,0" Name="btnReverseJulian" VerticalAlignment="Top" Width="275" Foreground="#FF00B1FF" BorderBrush="#FF00B1FF" />
<Button BorderBrush="#FF00B1FF" Content="Callout Form" Foreground="#FF00B1FF" Height="72" HorizontalAlignment="Left" Margin="81,412,0,0" Name="btnCalloutform" VerticalAlignment="Top" Width="275" />
<Image Height="76" HorizontalAlignment="Left" Margin="120,511,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="186" Source="/RSG%20Engineer;component/Images/k3_rsg_rgb_Small.png" />
</Grid>
</Grid>
<toolkit:TransitionService.NavigationInTransition>
<toolkit:NavigationInTransition>
<toolkit:NavigationInTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardIn"/>
</toolkit:NavigationInTransition.Backward>
<toolkit:NavigationInTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardIn"/>
</toolkit:NavigationInTransition.Forward>
</toolkit:NavigationInTransition>
</toolkit:TransitionService.NavigationInTransition>
<toolkit:TransitionService.NavigationOutTransition>
<toolkit:NavigationOutTransition>
<toolkit:NavigationOutTransition.Backward>
<toolkit:TurnstileTransition Mode="BackwardOut"/>
</toolkit:NavigationOutTransition.Backward>
<toolkit:NavigationOutTransition.Forward>
<toolkit:TurnstileTransition Mode="ForwardOut"/>
</toolkit:NavigationOutTransition.Forward>
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>
<!--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>-->
答案 0 :(得分:2)
右键单击Images文件夹,然后单击添加&gt;&gt;现有项目 浏览到正确的位置并找到该文件。单击“确定”,文件将导入项目中。
让我们看一下导入文件的属性。默认构建操作设置为“资源”。现在让我们添加Image控件并显示图像。
<Image Source=”/PhoneApp1;component/Images/k3_rsg_rgb_Small.png” />
正如你所看到的那样,虽然它没有任何问题,但却是一条稍微复杂的路径。它工作得很好。现在让我们尝试将图像BuildAction设置为Content。将其设置为内容时,请记住将“复制到输出文件夹”设置为“始终复制”。现在我们需要修改XAML
<Image Source=”/Images/k3_rsg_rgb_Small.png” />
可以查看原帖: http://invokeit.wordpress.com/2011/09/30/images-and-build-actio-settings-in-wp7/