elw00d / consoleframework

Cross-platform toolkit for easy development of TUI applications.
http://elw00d.github.io/consoleframework
MIT License
550 stars 63 forks source link

"Property xmlns not found" when trying to set root XML namespace #65

Closed ForNeVeR closed 4 years ago

ForNeVeR commented 4 years ago

To simplify compatibility with existing XAML tooling (e.g. Rider XAML editor), I'd like to set my namespaces in the XAML file itself, for example:

<Window xmlns="clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework"
                               MinHeight="10" MinWidth="25"
                               Title="Commits">
    <Panel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <TextBlock>Fenrir</TextBlock>
    </Panel>
</Window>

But this doesn't work: when I try to load this file, it throws an exception:

Unhandled exception. System.InvalidOperationException: Property xmlns not found.
   at Xaml.XamlParser.processAttribute(String attributePrefix, String attributeName, String attributeValue)
   at Xaml.XamlParser.createFromXaml(String xaml, Object dataContext)
   at Xaml.XamlParser.CreateFromXaml[T](String xaml, Object dataContext, List`1 defaultNamespaces)
   at Fenrir.Ui.EntryPoint.loadFromXaml[a](String resourceName, CommitsViewModel dataContext) in D:\X-Files\Projects\Fenrir\Fenrir.Ui\EntryPoint.fs:line 22
   at Fenrir.Ui.EntryPoint.run(String path) in D:\X-Files\Projects\Fenrir\Fenrir.Ui\EntryPoint.fs:line 29
   at Fenrir.Program.main(String[] argv) in D:\X-Files\Projects\Fenrir\Fenrir\Program.fs:line 187

I think that ConsoleFramework's XAML reader should respect well-known XML xmlns="" idiom.

elw00d commented 4 years ago

I see,

Actually, you can omit xmlns="..." if you want to use classes from default namespace ConsoleFramework.Controls.

And while it doesn't work with xmlns= you can insert

xmlns="clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework"

to get XAML editor working

and remove it when starting app.

This is the only workaround for now :-(

ForNeVeR commented 4 years ago

Actually, you can omit xmlns="..." if you want to use classes from default namespace ConsoleFramework.Controls.

Yes, but it requires to pass all the "default" namespaces to XamlParser.CreateFromXaml, like it is done here in the framework code: https://github.com/elw00d/consoleframework/blob/87ae9a527fb3e1dee7d1a52338909d4429c5c5ac/ConsoleFramework/ConsoleApplication.cs#L191-L196

I don't use this approach because the editor doesn't know about namespaces passed this way, and I want to utilize my editor tooling as much as possible.

And while it doesn't work with xmlns= you can insert

xmlns="clr-namespace:ConsoleFramework.Controls;assembly=ConsoleFramework"

to get XAML editor working

and remove it when starting app.

This is the only workaround for now :-(

As a workaround, I ended up just using the namespaced variant everywhere, which works equally well.

elw00d commented 4 years ago

I think it is fixed now, please give a try )