这可能是我想念的简单事情。我有一个 png 文件,我想在我的 WPF 窗口中将其用作 * Image * 控件的来源。我通过“项目属性”>“资源”>“添加现有文件”添加了这个 PNG 文件,首先作为链接文件(然后在它不起作用时作为嵌入文件)。然后我将 XAML 文件中的图像控件的 * Source * 添加到此文件中。不涉及代码,简单点击。
恼人的问题是,当我设计 WPF 窗口时,图像会显示。当我运行它时,它没有。什么都没有出现。
更新:在下面添加了 XAML 代码
<Window x:Class="Server.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="SERVER" Height="467.91" Width="620.522">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF080C59" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Button x:Name="btnConnect" Content="Connect" HorizontalAlignment="Left" Height="30" Margin="425,34,0,0" VerticalAlignment="Top" Width="134" Click="btnConnect_Click"/>
<Button x:Name="btnDisconnect" Content="Disconnect" HorizontalAlignment="Left" Height="35" Margin="425,69,0,0" VerticalAlignment="Top" Width="134" Click="btnDisconnect_Click"/>
<TextBlock x:Name="txtLog" HorizontalAlignment="Left" Margin="416,160,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="161" Width="87" Background="#FFFFF5F5" Text="LOG:"/>
<TextBox x:Name="txtMsg" HorizontalAlignment="Left" Height="23" Margin="416,326,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="112"/>
<Button x:Name="btnSend" Content="Send" HorizontalAlignment="Left" Height="35" Margin="425,120,0,0" VerticalAlignment="Top" Width="134" Click="btnSend_Click"/>
<ListView x:Name="lsvClients" Height="67" Margin="46,212,260,0" VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<Image HorizontalAlignment="Left" Height="100" Margin="31,10,0,0" VerticalAlignment="Top" Width="101" Source="pack://siteoforigin:,,,/images/ServerMainLogo.png"/>
</Grid>
</Window>
我错过了什么?谢谢