golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

[Unity] Binding to an object other than BaseComponent

30 May 2014, 15:41

Hi all,

I'm trying to create a binding between an UI element dependency property and an object property but Noesis.Binding accepts only BaseComponent object as a source.

http://www.noesisengine.com/docs/Gui.Core.Binding.html here it says "The Source can be a Dependency Property, or a "normal" property from an object that implements the INotifyChange interface". Am I missing something?

Thanks in advance
 
KeldorKatarn
Posts: 193
Joined: 30 May 2014, 10:26

Re: [Unity] Binding to an object other than BaseComponent

30 May 2014, 16:08

Thumbs up for this one since that would be quite a limitation...
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] Binding to an object other than BaseComponent

30 May 2014, 17:57

If you're creating a user control you have to bind to the dependency properties of the user control.

If you're using the a plain view and a view model you can bind to normal Properties (that should invoke NotifyPropertyChanged) of the vm. As far as I know only BaseComponent implements NotifyPropertyChanged() so your view model has to inherit from BaseComponent.

If I'm wrong someone may correct me. :)
 
KeldorKatarn
Posts: 193
Joined: 30 May 2014, 10:26

Re: [Unity] Binding to an object other than BaseComponent

30 May 2014, 20:16

Well first of all DependencyProperties are on the View, not the ViewModel, so that should be irrelevant.

A ViewModel in WPF/Silverlight can be any plain old class. It needs to implement INotifyPropertyChanged if change of data should be dynamically bound. For one time databinding not even that is necessary.

I don't see why I have to derive from a base class to get an implementation of INotifyPropertyChanged. Why can't I just implement that interface myself? All it does is trigger the PropertyChanged event declared in that interface wiht the property name as a string argument. Why do I need a base class for that?

If this is true that is a HUGE limitation. Databinding should work against any class, that's the whole point behind databinding.
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] Binding to an object other than BaseComponent

31 May 2014, 02:05

If you take a closer look at the "NotifyPropertyChanged()" method in the BaseComponent class you can see that it just calls another method that in the end just wraps a function call to C++. So I guess you're kinda bound to BaseComponent.

And yes, it's a limitation but at least for me that's one of the limitations that I can work around.
 
User avatar
jsantos
Site Admin
Posts: 3805
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Binding to an object other than BaseComponent

02 Jun 2014, 18:10

We are fully aware of this limitation. We will try to improve this in future versions. For now, the workaround to avoid having to inherit from our base class is containing the Noesis.BaseComponent inside your class.
 
golgepapaz
Topic Author
Posts: 43
Joined: 01 Aug 2013, 01:59

Re: [Unity] Binding to an object other than BaseComponent

04 Jun 2014, 07:59

We are fully aware of this limitation. We will try to improve this in future versions. For now, the workaround to avoid having to inherit from our base class is containing the Noesis.BaseComponent inside your class.
So the documentation is wrong or am I looking the wrong place?
 
User avatar
sfernandez
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: [Unity] Binding to an object other than BaseComponent

06 Jun 2014, 02:11

Hi all,

I'm trying to create a binding between an UI element dependency property and an object property but Noesis.Binding accepts only BaseComponent object as a source.

http://www.noesisengine.com/docs/Gui.Core.Binding.html here it says "The Source can be a Dependency Property, or a "normal" property from an object that implements the INotifyChange interface". Am I missing something?

Thanks in advance
When using NoesisGUI from Unity you don't have to implement any interface, the source object only has to inherit from Noesis.BaseComponent and use the NotifyPropertyChange() method to notify the system about property changes.

As Jesus said, we want to remove this limitation and improve our C# API to resemble as much as possible WPF API.
So the documentation is wrong or am I looking the wrong place?
This documentation is not very clear because it refers to the Native SDK, we will improve it for next versions.
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: [Unity] Binding to an object other than BaseComponent

24 Jul 2014, 02:06

Would it eventually be possible to use ViewModels generated with an MVVM framework such as uFrame with Noesis GUI? uFrame is a MVVM framework for Unity. See: http://invertgamestudios.com/

I have tried to remake the Command sample in combination with uFrame. uFrame's generated ViewModel for Noesis' Command sample looks like this:
public partial class NoesisChatViewModel : ViewModel {

    public readonly P<System.String> _InputProperty = new P<string>();
    public readonly P<System.String> _OutputProperty = new P<string>();

    private ICommand _SayHelloCommand;

    public virtual string Input {
        get {
            return _InputProperty.Value;
        }
        set {
            _InputProperty.Value = value;
        }
    }

    public virtual string Output {
        get {
            return _OutputProperty.Value;
        }
        set {
            _OutputProperty.Value = value;
        }
    }

    public virtual ICommand SayHelloCommand {
        get {
            return _SayHelloCommand;
        }
        set {
            _SayHelloCommand = value;
        }
    }
}
As you can see it's currently not possible to use the ViewModel as a resource in the XAML because:

1) It doesn't derive from Noesis.SerializableComponent. However if I understand correctly you are looking to lift that requirement.

2) uFrame's generated files are all in the global namespace, but fortunately namespaces in code generation are on the roadmap for uFrame 1.3.

3) uFrame's ICommand is not the same as BaseCommand nor the same as Microsoft's ICommand. Would that be an obstacle? The uFrame developers are about to revise some core stuff in the following next weeks and are now open to suggestions, so maybe you could get in touch with them. Currently uFrame's ICommand looks like this:
public delegate void CommandEvent();

/// <summary>
/// The base command interface for implementing a command in a ViewModel
/// </summary>
public interface ICommand
{
    event CommandEvent OnCommandExecuted;

    event CommandEvent OnCommandExecuting;
    object Sender { get; set; }
    object Parameter { get; set; }

    IEnumerator Execute();
}
In the meantime I know I can write Views to bind ViewModel properties to XAML controls, but it's redundant and error-prone. Would be a much more elegant solution if you could just plug in the ViewModel.
Last edited by movra on 24 Jul 2014, 07:41, edited 1 time in total.
 
wckdspn
Posts: 67
Joined: 18 Aug 2012, 23:14

Re: [Unity] Binding to an object other than BaseComponent

24 Jul 2014, 02:51

In the meantime I know I can write Views to bind ViewModel properties to XAML controls, but it's redundant and error-prone. Would be a much more elegant solution if you could just plug in the ViewModel.
I have no idea what you are talking about here, can you elaborate?

Who is online

Users browsing this forum: dengfan and 13 guests