-
- golgepapaz
- Posts: 43
- Joined:
[Unity] Binding to an object other than BaseComponent
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
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:
Re: [Unity] Binding to an object other than BaseComponent
Thumbs up for this one since that would be quite a limitation...
Re: [Unity] Binding to an object other than BaseComponent
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.
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:
Re: [Unity] Binding to an object other than BaseComponent
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.
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.
Re: [Unity] Binding to an object other than BaseComponent
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.
And yes, it's a limitation but at least for me that's one of the limitations that I can work around.
Re: [Unity] Binding to an object other than BaseComponent
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
- Posts: 43
- Joined:
Re: [Unity] Binding to an object other than BaseComponent
So the documentation is wrong or am I looking the wrong place?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.
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: [Unity] Binding to an object other than BaseComponent
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.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
As Jesus said, we want to remove this limitation and improve our C# API to resemble as much as possible WPF API.
This documentation is not very clear because it refers to the Native SDK, we will improve it for next versions.So the documentation is wrong or am I looking the wrong place?
Re: [Unity] Binding to an object other than BaseComponent
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:
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:
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 tried to remake the Command sample in combination with uFrame. uFrame's generated ViewModel for Noesis' Command sample looks like this:
Code: Select all
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;
}
}
}
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:
Code: Select all
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();
}
Last edited by movra on 24 Jul 2014, 07:41, edited 1 time in total.
Re: [Unity] Binding to an object other than BaseComponent
I have no idea what you are talking about here, can you elaborate?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.
Who is online
Users browsing this forum: dengfan and 13 guests