alternetsoft / AlternetUI

MIT License
22 stars 2 forks source link

Error reading Uixml: Attributes aren't allowed on element properties #120

Closed Shadowblitz16 closed 5 months ago

Shadowblitz16 commented 5 months ago

What does this mean?

Error reading Uixml: Attributes aren't allowed on element properties Line 17, position 4.
    File: Views.EditorView.uixml Ln: 17 Ch: 4
    Exception type: XamlX.XamlParseException
<Window xmlns="http://schemas.alternetsoft.com/ui/2021"
        xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
        x:Class="SMBY.EditorView"
        Title="SMBY Editor" StartLocation="CenterScreen"
        Size="800,600" Layout="Vertical">

        <Window.Menu>
                <MainMenu>
                        <MenuItem Text="File">
                                <MenuItem Text="Open"/>
                                <MenuItem Text="Save"/>
                                <MenuItem Text="Save As.."/>
                                <MenuItem Text="-"/>
                                <MenuItem Text="Exit"/>
                        </MenuItem>
                        <MenuItem Text="Tools">
                                <MenuItem Text="World Editor" Command="{Binding EditWorld}"/>
                        </MenuItem>
                </MainMenu>
        </Window.Menu>

        <SMBY.WorldView DataContext="{Binding World}" Visible="{Binding IsWorldMode}"/>

</Window>
<Window xmlns="http://schemas.alternetsoft.com/ui/2021"
        xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
        x:Class="SMBY.WorldView"
        Layout="Vertical">

        <Control UserPaint="true" VerticalAlignment="Fill" BackColor="Black"/>
        <HorizontalStackPanel>
                <Button Text="Select"/>
                <Button Text="Erase"/>   
        </HorizontalStackPanel>

</Window>

it seems that it doesn't like this...

<SMBY.WorldView DataContext="{Binding World}" Visible="{Binding IsWorldMode}"/>

using Alternet.UI;
using SMBY;

public enum EpisodeMode 
{
    World,
    Level
}

public enum WorldToolMode
{
    Select,
    Erase
}

public enum LevelToolMode
{
    Select,
    Erase
}

public record Episode : SingletonModel<Episode>
{

    public string      Name 
    {
        get => Get<string>("New Episode");
        set => Set<string>(value);
    }
    public EpisodeMode Mode 
    {
        get => Get<EpisodeMode>(EpisodeMode.World);
        set => Set<EpisodeMode>(value);
    }
    public World       World 
    {
        get => Get<World>(World.Empty);
        set => Set<World>(value);
    }

    public ICommand    EditWorld { get; }
    public bool IsWorldMode => Mode == EpisodeMode.World;

    public Episode()
    {
        EditWorld = new Command((s) =>
        {
            Mode = EpisodeMode.World;
        });

    }
}

namespace SMBY;
public record World : Model
{
    public string Name 
    {
        get => Get<string>("New World");
        set => Set<string>(value);
    }

    public static readonly World Empty = new();
}

using Alternet.UI;

namespace SMBY;

public partial class EditorView : Window
{

    public EditorView()
    {
        InitializeComponent();
        DataContext = Episode.Instance;

    }
}
generalloki commented 5 months ago

All I can say about Binding - do not use it until it is rewritten. Current implementation uses dictionaries for storing bindable properties and it is not good for performance. Due to this all standard properties in UI made not bindable.

Shadowblitz16 commented 5 months ago

ok :(

generalloki commented 5 months ago

I am moving this to discussions as fixing this issue will require rewrite of Binding source code. I will post here an update when we move forward with this issue.