sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

XAML support #969

Closed ghost closed 8 years ago

ghost commented 8 years ago

Is there a way I can use XAML with JSIL? I am creating a C# to HTML5 GUI framework and would like it to be usable with XAML. Currently, layouts can be built like this:

    public class MainForm : WebForm
    {
        public MainForm()
        {
            Controls = new Layout()
            {
                new TextBlock()
                {
                    Text = "SharpJS WebForms Demo",
                    FontStyle = new FontStyle()
                    {
                        FontSize = 24,
                        FontWeight = JSIL.Dom.Styles.FontWeight.Bold
                    },
                    TextAlign = JSIL.Dom.Styles.TextAlign.Center,
                },
                new TextBlock()
                {
                    Text = "Enter some text:",
                },
                new TextBox(),
                new Button()
                {
                    Text = "OK",
                },
            };
        }
    }

I want to be able to specify this instead:

<WebForm x:Class="WebFormsTemplate.MainWFForm"
    xmlns="clr-namespace:ExaPhaser.WebForms;assembly=ExaPhaser.WebForms"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:ExaPhaser.WebForms.Controls;assembly=ExaPhaser.WebForms">
    <WebForm.Controls>
        <controls:TextBlock Text="Hello, World!" />
    </WebForm.Controls>
</WebForm>

Does anyone know how I can implement this? Please do not mention CSHTML5, as it is closed source and my project is open source.

kg commented 8 years ago

The body of your issue seems to be mangled.

One option for XAML would be to feed the XAML through the normal MS build pipeline and translate the managed code their compiler generates. Not sure how hard that would be, though...

ghost commented 8 years ago

I currently tried referencing System.Xaml, but this references all the PresentationFramework and PresentationCore assemblies, which do not seem to decompile well with JSIL. I guess I'll try writing a custom implementation or something.

ghost commented 8 years ago

I have, however, been having trouble with the dynamic keyword. Is there anything special I should do when using dynamic with JSIL, like the DynamicAttribute or something?

kg commented 8 years ago

Yeah, I think at present you wouldn't want to cross-compile the implementation. Just cross-compile the code generated by the compiler from your XAML files. This is similar to what is done for XML Serializer assemblies.

ghost commented 8 years ago

Is there a way I can use XAML without referencing PresentationCore and PresentationFramework? These aren't necessary but my compiler insists that I reference them.

iskiselev commented 8 years ago

@0xFireball. have you looked on Fayde projects? They implement XAML in html/js on top of canvas. It would be great if somebody would implement bindings to it, and it would be great if they will be wpf/silverlight compatible.

iskiselev commented 8 years ago

@0xFireball, could you describe what type of problems do you have with dynamic?

iskiselev commented 8 years ago

Also it may worth to look on https://github.com/Perspex/Perspex, it should be much easier to port it to be used with JSIL.

ghost commented 8 years ago

Thanks! I'm trying to make an open source alternative to CSharp/Xaml for Html5

ghost commented 8 years ago

I resolved the issue with dynamic. Sorry about that, it was bad implementation on my part.

ghost commented 8 years ago

Hello, if this is still relevant, I succeeded in creating a usable UI framework built upon JSIL! https://github.com/exaphaser/SharpJS

After writing the UI framework, I wrote another library (It's in the repo too that would allow users to port WinForms projects to the web.)

It's obviously not production ready at the moment (I didn't spend that much time on it), but it's a start for a compatibility layer for WinForms. At the moment, you still have to recompile the project to reference my WinFormsCompat lib (or you could hack the assembly).

I also made C# bindings for some of jQuery (as much as the whole framework needed, I might add more) and WebSockets, AJAX, JS Buffers, Printing, Blob saving, and uploading.

I also have some bindings for DOM, which I used in some libs.

I paused development a couple months ago, but I'm restarting development again. This time, I'm going to improve the UI framework and maybe try adding some XAML-inspired UI.

I'm looking at Fayde for ideas for now.

The extensions are licensed under GPLv3 in the repository, but if a merge would help JSIL, I would be delighted to give the changes back to JSIL under the MIT license. Just please let me know.

ghost commented 8 years ago

Unfortunately I messed up massively with Git, and that repo does not share a history with JSIL :( and I had to manually merge changes. That was a big mistake, but I don't want to lose my own commit history now. If anyone has a solution please let me know, I would really appreciate it.

kg commented 8 years ago

Worst case you could generate a single massive merge commit (ugh) by doing a diff of the whole tree against JSIL. Maybe then you could split the commit up into logical chunks.