本文介绍了我可以在Metro ui javascript代码中使用在C#中创建的对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢C#,并且对它很熟悉,但是我也想使用HTML5/JavaScript来管理Windows 8 Metro应用程序的UI.那么,如何从Java文件中的C#库中导入和使用对象?

这里的示例是一个空HTML5/JS项目的起始JS代码...

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    var app = WinJS.Application;

    app.onactivated = function (eventObject) {
        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            if (eventObject.detail.previousExecutionState !== Windows.ApplicationModel.Activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize 
                // your application here.
            } else {
                // TODO: This application has been reactivated from suspension. 
                // Restore application state here.
            }
            WinJS.UI.processAll();
        }
    };

    app.oncheckpoint = function (eventObject) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the 
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // eventObject.setPromise(). 
    };

    app.start();
})();

我可以引入并使用用C#编写的JS中的库和对象吗?

我感到很沮丧,他们似乎将C#与基于HTML5的项目隔离开来...

解决方案

您绝对可以做到这一点.这就是Windows 8和新应用程序模型的优点.有很多地方可以开始学习.

从此处开始: http://msdn. microsoft.com/en-us/library/windows/apps/br230301(v=vs.110).aspx 您可以在上面的链接中进一步细化,该链接还链接到真实的基本示例. http://msdn.microsoft.com/zh-CN /library/windows/apps/hh779077(v=vs.110).aspx

简而言之,您将在C#中创建Metro类库,然后将C#的输出类型从类库"设置为WinMD.然后,您可以在javascript项目中引用和使用该库.

http://msdn.microsoft.com上,有许多有关构建Metro应用程序的文档. /en-us/library/windows/apps

I really like C# and I am familiar with it, but I also want to use HTML5/JavaScript to manage the UI for my Windows 8 Metro app. So, how can I import and use objects from a library made in C# in the Javascript files?

Example here is the starting JS code for an empty HTML5/JS project...

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    var app = WinJS.Application;

    app.onactivated = function (eventObject) {
        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            if (eventObject.detail.previousExecutionState !== Windows.ApplicationModel.Activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize 
                // your application here.
            } else {
                // TODO: This application has been reactivated from suspension. 
                // Restore application state here.
            }
            WinJS.UI.processAll();
        }
    };

    app.oncheckpoint = function (eventObject) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the 
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // eventObject.setPromise(). 
    };

    app.start();
})();

Can I pull in and use libraries and objects in JS that are written in C#?

I was kind of bummed they appear to segregate C# from HTML5 based projects...

解决方案

You absolutely can do this. This is the beauty of the Windows 8 and the new application model. There are a lot of places to start and look at.

Start here: http://msdn.microsoft.com/en-us/library/windows/apps/br230301(v=vs.110).aspx You can drill down further in the above link where it also links to a real basic sample. http://msdn.microsoft.com/en-us/library/windows/apps/hh779077(v=vs.110).aspx

In a nutshell, you'll create a metro class library in C# and then set the output type of your C# from a "Class Library" to a WinMD. You can then reference and use that library in your javascript project.

There is a lot of documentation on building metro apps available at http://msdn.microsoft.com/en-us/library/windows/apps

这篇关于我可以在Metro ui javascript代码中使用在C#中创建的对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:55