c# - 如何在初始化渲染器之前调用方法 [Wpf]

标签 c# .net wpf

关于标题的问题。我创建了一个 Steam 应用程序,并使用 Steamworks.NET 进行 Steam 初始化。网站说:

Open the Visual Studio solution (.sln) file, build both targets one for Windows and one for OSX & Linux. (Optional if you downloaded a prebuilt version) Reference the built assembly (Steamworks.NET.dll) in your project. Start coding! Call SteamAPI.Init() before initializing your renderer.

我尝试用加载事件调用它,但每次都崩溃了。

这里是我的调用代码:

private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) {
  SteamAPI.Init();
  SteamAPI.RestartAppIfNecessary(new AppId_t(911310));
}

我试过:

public MainWindow()
    {
        SteamAPI.Init();
        InitializeComponent();
    }

如何在渲染前调用该方法?


已解决

使用不同的 SDK 解决。

最佳答案

使用 Application.Startup事件。

您可以像这样将其附加到“App.xaml”文件中:

<Application
    x:Class="SomeApp.App.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SomeApp.App"
    Startup="App_OnStartup">
    <Application.Resources>       
    </Application.Resources>
</Application>

然后在“App.xaml.cs”中添加处理程序:

public partial class App : Application
{
    private void App_OnStartup(object sender, StartupEventArgs e)
    {
        SteamAPI.Init();
    }
}

关于c# - 如何在初始化渲染器之前调用方法 [Wpf],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51523131/

相关文章:

c# - 将 Javascript 用于 WPF 中的 Google map API

c# - 在 C# 中进行游戏开发需要使用什么?

c# - 在 ASP.NET 中查找给定周(月)后的日期

c# - 使用 Ninject 在类中注入(inject)字符串属性

.net - 在 .NET 中编写计划的 Windows 服务

c# - Microsoft.Win32.SaveFileDialog 有效文件名问题

c# - 尝试运行代码时出错 : Debugger operation failed, native 错误 = 找不到指定的文件

c# - WCF 反序列化丢失子集合

c# - WPF 应用程序中的安全问题

c# - Windows XP 上的 WPF 视觉问题