locked
HTML5, CSS, and .NET Framework?

    Question

  • I'm under the impression that if one develops Windows 8 Modern UI apps using HTML5 then the .NET Framework is not available for use (it's only available for the VB \ VC#, XAML developers). Is this true, and if so, is there something that takes the places of the .NET capability?

    TIA,

    edm2

    Sunday, January 27, 2013 12:26 AM

Answers

  • The .NET framework isn't available directly, that's true, but you can write a WinRT component in C# or VB and have it's public interface projected into JavaScript. In that sense you can write functions in .NET languages and invoke them from JavaScript, no problem. In other words, you can wrap .NET functionality in such a component, so long as you're not using UI/graphics stuff which cannot be shared with HTML/CSS/JavaScript.

    Visual Studio has a project template for exactly this. In your JavaScript solution, right click the solution, select Add > New Project..., then select the C# or VB language followed by the Windows Runtime Component option. This will give you a component project with this code as the default structure:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace WindowsRuntimeComponent1
    {
        public sealed class Class1
        {
        }
    }

    You need to then right click your JS project, select Add Reference, select Solution on the left and you'll see the WinRT component show up in the list. Check that, press OK, and voila! the component's namespace and classes are available directly in JS.

    For more details, you can see the walkthrough on this in the docs or Chapter 16 of my free ebook linked below.

    Kraig

    Author, Programming Windows 8 Apps in HTML, CSS, and JavaScript, a free ebook from Microsoft Press.


    Sunday, January 27, 2013 6:17 AM

All replies

  • The .NET framework isn't available directly, that's true, but you can write a WinRT component in C# or VB and have it's public interface projected into JavaScript. In that sense you can write functions in .NET languages and invoke them from JavaScript, no problem. In other words, you can wrap .NET functionality in such a component, so long as you're not using UI/graphics stuff which cannot be shared with HTML/CSS/JavaScript.

    Visual Studio has a project template for exactly this. In your JavaScript solution, right click the solution, select Add > New Project..., then select the C# or VB language followed by the Windows Runtime Component option. This will give you a component project with this code as the default structure:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace WindowsRuntimeComponent1
    {
        public sealed class Class1
        {
        }
    }

    You need to then right click your JS project, select Add Reference, select Solution on the left and you'll see the WinRT component show up in the list. Check that, press OK, and voila! the component's namespace and classes are available directly in JS.

    For more details, you can see the walkthrough on this in the docs or Chapter 16 of my free ebook linked below.

    Kraig

    Author, Programming Windows 8 Apps in HTML, CSS, and JavaScript, a free ebook from Microsoft Press.


    Sunday, January 27, 2013 6:17 AM
  • Excellent answer. And I will download your book!

    edm2

    Sunday, January 27, 2013 4:20 PM