2

我正在学习 DirectX,但我不太了解 C++,所以我决定改用 SharpDX。但是我被困在 C++ 中的这一部分,他们使用 TypedEventHandler 中的函数地址,但我不知道如何用 C# 编写它?任何人都可以帮忙吗?

ref class App sealed : public IFrameworkView
{
public:
virtual void Initialize(CoreApplicationView^ AppView)
{
    AppView->Activated += ref new TypedEventHandler
        <CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
}
virtual void SetWindow(CoreWindow^ Window) {}
virtual void Load(String^ EntryPoint) {}
virtual void Run() {}
virtual void Uninitialize() {}

void OnActivated(CoreApplicationView^ CoreAppView, IActivatedEventArgs^ Args)
{
    CoreWindow^ Window = CoreWindow::GetForCurrentThread();
    Window->Activate();
}
};

到目前为止我的转换

internal class App : IFrameworkView
{
    public void Initialize(CoreApplicationView AppView)
    {
        // Call OnActivated() when the Activated event is triggered
        AppView.Activated += new TypedEventHandler<CoreApplicationView, IActivatedEventArgs>(this,this.OnActivated);

    }
    public void SetWindow(CoreWindow Window) {}
    public void Load(String EntryPoint) {}
    public void Run() {}
    public void Uninitialize() {}

    public void OnActivated(CoreApplicationView CoreAppView, IActivatedEventArgs Args)
    {
        CoreWindow Window = CoreWindow.GetForCurrentThread();
        Window.Activate();
    }

}
4

1 回答 1

6

您不需要 C# 事件连接的“this”参数:

public sealed class App : IFrameworkView
{
    public virtual void Initialize(CoreApplicationView AppView)
    {
        AppView.Activated += new TypedEventHandler <CoreApplicationView, IActivatedEventArgs>(OnActivated);
    }

    public virtual void SetWindow(CoreWindow Window)
    {
    }
    public virtual void Load(string EntryPoint)
    {
    }
    public virtual void Run()
    {
    }
    public virtual void Uninitialize()
    {
    }

    public void OnActivated(CoreApplicationView CoreAppView, IActivatedEventArgs Args)
    {
        CoreWindow Window = CoreWindow.GetForCurrentThread();
        Window.Activate();
    }
}
于 2013-06-27T02:05:08.167 回答