[英]Dotnet Core with glade cannot find resource
我用 gtk 和 glade 創建了 dotnet 核心項目。
這是我的項目結構。
程序.cs
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// Initialize Gtk.
Application.Init();
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
Application.Run();
}
}
主窗口.cs
public class MainWindow : Window
{
public MainWindow() : this(new Builder("MainWindow.glade")) { }
public MainWindow(Builder builder) : base(builder.GetObject("MainWindow").Handle)
{
builder.Autoconnect(this);
}
}
而且,我已經將資源文件添加到 csproj。
<ItemGroup>
<None Remove="MainWindow.glade" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainWindow.glade" />
</ItemGroup>
我試圖在 Main() 中調用主窗口,但總是收到此錯誤。
Unhandled exception. System.ArgumentException: Cannot get resource file 'MainWindow.glade' (Parameter 'resource_name')
at Gtk.Builder..ctor(Assembly assembly, String resource_name, String translation_domain)
at Gtk.Builder..ctor(String resource_name)
at helloOpenTK.MainWindow..ctor() in helloOpenTK/MainWindow.cs:line 12
at helloOpenTK.Program.Main(String[] args) in helloOpenTK/Program.cs:line 21
您能否向我建議如何更改文件夾結構以使其正常工作?
先感謝您。
在嘗試使用gtkapp template創建新項目后,我找到了解決方案。
我更改了 csproj 中的配置,它可以運行而不再出現錯誤。
<ItemGroup>
<None Remove="**\*.glade" />
<EmbeddedResource Include="**\*.glade">
<LogicalName>%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.