Wouterdek/NodeNetwork

Tag property on NodeViewModel

Kiwifranky opened this issue · 2 comments

Hi,

thank you for this really great tool! I would like to ask if it is possible to ad a Tag property of type object to the NodeViewModel.
It would make it easier - hopefully not only for me - to attach additional information to a NodeViewModel.

Thanks again...

Hi, the recommended way to add data to nodes is to create custom node types.

If you want a node type with a tag, you could create something like this:

public class TaggedNode : NodeViewModel
{
    static TaggedNode ()
    {
        Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor<TaggedNode>));
    }

    public object Tag 
    {
        get => _tag;
        set => this.RaiseAndSetIfChanged(ref _tag, value);
    }
    private object _tag;
}

Thanks for the hint!

I tried to inherit but because I forgot to register with Splat it was not working as expected.

Silly mistake....