8,750
社区成员
发帖
与我相关
我的任务
分享
写了一个支持插件的软件A,就是在程序里调用另一个程序集B,发现:单独运行B 程序正常,能够显示各种资源包括图片图标能够正常显示,但当在A里面调用B显示出来的时候,图片资源就显示不出来了。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Flybird.Test.程序集资源"
mc:Ignorable="d"
Title="显示程序集资源图片" Height="450" Width="800">
<Window.Resources >
<BitmapImage x:Key="mycad1" UriSource="/Resources/cad1.ico"/>
</Window.Resources>
<StackPanel >
<TextBlock Text="下面是引用资源一个图标:"/>
<Image Source="{StaticResource mycad1 }" Width="32" Height="32" Margin="5" HorizontalAlignment="Left"/>
<TextBlock Text="下面是引用路径一个图标:"/>
<Image Source="/Resources/cad1.ico" Width="48" Height="48" HorizontalAlignment="Left" Margin="5"/>
</StackPanel>
</Window>
上面是被调用的程序集B的窗体代码,cad1.ico是一个图标,生成方式:resources
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:测试引用程序集"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel >
<Button Content="打开程序集窗体" Click="Button_Click" Width="150" Height="38" HorizontalAlignment="Left" />
<Button Content="直接打开exe" Click="Button_Click_1" Width="150" Height="38" HorizontalAlignment="Left" />
</StackPanel>
</Window>
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim frm As New Flybird.Test.程序集资源.MainWindow
frm.Show()
End Sub
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
Dim path As String = AppDomain.CurrentDomain.BaseDirectory
Dim spath As String = "..\..\..\程序集资源\bin\Debug\程序集资源测试.exe"
Dim f As String = IO.Path.Combine(path, spath)
'f = IO.Path.GetFullPath(f)
'If IO.File.Exists(f) Then
' Dim p As New Process()
' Process.Start(f)
'End If
f = IO.Path.GetFullPath(f)
If IO.File.Exists(f) Then
Dim p As New Process()
Process.Start(f)
End If
End Sub
End Class
这是程序A的前台和后台代码
中间的那张图片就是通过程序集打开的,右边的就是直接运行的,通过程序集运行的显示不了图元。