[Unity] Binding to the nested properties.
Hi!
I'm trying to display the property that belongs not to the object set in DataContest itself, but rather the property of property of that object. In this case property prime_Target.object_ID of SpaceShip class object:
But adding the following in XAML doesn't produce the expected results, the field remains empty after assigning new value to prime_Target.
What's worse, is that Unity freezes after exiting play mode. Any advise on how to correctly handle this would be appreciated
. Thanks!
I'm trying to display the property that belongs not to the object set in DataContest itself, but rather the property of property of that object. In this case property prime_Target.object_ID of SpaceShip class object:
Code: Select all
public class LocalObject: Noesis.BaseComponent {
...
public string object_ID;
}
public class SpaceShip: LocalObject {
private LocalObject _prime_Target;
public LocalObject prime_Target {
get { return _prime_Target; }
set {
if (_prime_Target != value) {
_prime_Target = value;
NotifyPropertyChanged("prime_Target");
}
}
}
}
public class ShipControlPanel : Noesis.UserControl {
public ShipControlPanel(SpaceShip currentship) {
SetDataContext(currentship);
}
}
Code: Select all
<TextBlock Text="{Binding prime_Target.object_ID}" Style="{StaticResource StatText}"/>

-
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: [Unity] Binding to the nested properties.
Hello! As far as I know, you can't bind to public fields, only to properties. So, try to replace
with this line
About Unity freezes - I'm also experiencing this problem. For me, killing UnityShaderCompiler process helps to "anti-freeze" Unity. I've reported issue, but Unity team seems to not pay much attention into it...
By the way, I'm fighting with Unity freezes for a long time (more than 1 year) - it's never was stable, especially if you use native plugins, threading, sockets, etc. So, instead of stopping "Play mode", I'm prefer to use this AutoHotkey shortcut (Windows+Shift+E) to restart Unity Editor:
Code: Select all
public string object_ID;
Code: Select all
public string object_ID { get; set; }
By the way, I'm fighting with Unity freezes for a long time (more than 1 year) - it's never was stable, especially if you use native plugins, threading, sockets, etc. So, instead of stopping "Play mode", I'm prefer to use this AutoHotkey shortcut (Windows+Shift+E) to restart Unity Editor:
Code: Select all
#+e::
Process, Close, Unity.exe
Run C:\Program Files (x86)\Unity\Editor\Unity.exe
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Re: [Unity] Binding to the nested properties.
Hello ai!
I adjusted code as you advised, but GUI still doesn't show this data. So I guess it wasn't the only problem or maybe this feature is not [correctly] implemented in Noesis plugin. It would be great to hear developers opinion on the matter.
Thanks for your advice anyway -- at least there is one error less in my scripts
.
Regarding freezes -- it's really annoying indeed. The Editor behavior is rather unpredictable ATM. It may return normally in edit mode after I spend quite a time in play mode trying various features, and yet it can freeze after entering and exiting play mode for a few seconds.
Killing UnityShaderCompiler process helping though, so thanks for the tip. And for the shortcut -- I hope I won't get used to it).
I adjusted code as you advised, but GUI still doesn't show this data. So I guess it wasn't the only problem or maybe this feature is not [correctly] implemented in Noesis plugin. It would be great to hear developers opinion on the matter.
Thanks for your advice anyway -- at least there is one error less in my scripts

Regarding freezes -- it's really annoying indeed. The Editor behavior is rather unpredictable ATM. It may return normally in edit mode after I spend quite a time in play mode trying various features, and yet it can freeze after entering and exiting play mode for a few seconds.
Killing UnityShaderCompiler process helping though, so thanks for the tip. And for the shortcut -- I hope I won't get used to it).
-
- ai_enabled
- Posts: 231
- Joined:
- Contact:
Re: [Unity] Binding to the nested properties.
DataContext binding should work for this case:
Also I recommend you to use NotifyPropertyChanged() at the LocalObject.object_id property to provide updates to the NoesisGUI:
Hope it helps!
Code: Select all
<TextBlock DataContext="{Binding prime_Target}" Text="{Binding object_ID}" Style="{StaticResource StatText}"/>
Code: Select all
private string _object_ID;
public string object_ID
{
get { return _object_ID; }
set
{
if (_object_ID != value)
{
_object_ID = value;
NotifyPropertyChanged("object_ID");
}
}
}
AtomicTorch Studio Pte. Ltd. http://atomictorch.com
Re: [Unity] Binding to the nested properties.
Got it, but I can't do it ATM since LocalObject is a parent class, and there is a bug with NotifyPropertyChanged() events declared in parent classes: viewtopic.php?f=3&t=435Also I recommend you to use NotifyPropertyChanged() at the LocalObject.object_id property to provide updates to the NoesisGUI:
Changing TexBlock description in xaml as you suggested didn't help unfortunately. But thanks for trying to help anyways! Cheers).
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [Unity] Binding to the nested properties.
Hi,Hi!
I'm trying to display the property that belongs not to the object set in DataContest itself, but rather the property of property of that object. In this case property prime_Target.object_ID of SpaceShip class object:
...
But adding the following in XAML doesn't produce the expected results, the field remains empty after assigning new value to prime_Target.
First of all you need to add the [Noesis.Extended] attribute to your classes, so we can register correctly in our system. The UserControl must also have the [Noesis.UserControlSource("<path_to_the_usercontrol_xaml_here>")] attibute, so we can load the associated xaml when your UserControl is created.
Next, as @ai_enabled suggested, bindings only work when used with C# properties, it won't work with simple fields.
I modified your code to the following, and it is working fine:
Code: Select all
[Noesis.Extended]
public class LocalObject : Noesis.BaseComponent {
public string object_ID { get; set; }
}
[Noesis.Extended]
public class SpaceShip : LocalObject {
private LocalObject _prime_Target;
public LocalObject prime_Target {
get { return _prime_Target; }
set
{
if (_prime_Target != value) {
_prime_Target = value;
NotifyPropertyChanged("prime_Target");
}
}
}
}
[Noesis.Extended]
[Noesis.UserControlSource("Assets/NoesisGUI/Samples/_Tests/_Test/_Test.xaml")]
public class ShipControlPanel : Noesis.UserControl {
public ShipControlPanel(SpaceShip currentship) {
SetDataContext(currentship);
}
}
Maybe your freezing problems are related to what is explained in this topic: viewtopic.php?f=3&t=92What's worse, is that Unity freezes after exiting play mode. Any advise on how to correctly handle this would be appreciated. Thanks!
Let me know if killing adb.exe process solves it.
Re: [Unity] Binding to the nested properties.
Hi,
Thanks for the tips, it's actually working now, at least to some degree
.
Thing is that in order to make it work, you have to assign 'non-null' value to corresponding property before calling 'ContentControl.SetContent' , otherwise it won't show the property in GUI.
So, the following code only works if you add myShip.prime_Target = myTargetOne before
_controlPanelContainer.SetContent(ControlPanel).
Just in case -- repro scene is attached.
EDIT:
Eventually setting reference property value to null at any pont in time breaks the binding. Thus the following wouldn't work after 3 seconds:
Thanks for the tips, it's actually working now, at least to some degree

Thing is that in order to make it work, you have to assign 'non-null' value to corresponding property before calling 'ContentControl.SetContent' , otherwise it won't show the property in GUI.
So, the following code only works if you add myShip.prime_Target = myTargetOne before
_controlPanelContainer.SetContent(ControlPanel).
Code: Select all
void Start()
{
var gui = GetComponent<NoesisGUIPanel>();
root = gui.GetRoot<Noesis.FrameworkElement>();
this._controlPanelContainer = root.FindName<Noesis.ContentControl>("controlPanelContainer");
myShip = new SpaceShip();
myTargetOne = new LocalObject ();
myTargetOne.Object_ID = "Hi brothers!";
myTargetTwo = new LocalObject ();
myTargetTwo.Object_ID = "Bye brothers!";
var ControlPanel = new ControlPanel(myShip);
myShip.prime_Target = myTargetOne; // w/o this line it won't show myShip.prime_Target.Object_ID
this._controlPanelContainer.SetContent(ControlPanel);
}
void Update () {
if ( Mathf.Repeat( Time.time, 1f) > 0.5f) myShip.prime_Target = myTargetOne;
else myShip.prime_Target = myTargetTwo;
}
}
EDIT:
Eventually setting reference property value to null at any pont in time breaks the binding. Thus the following wouldn't work after 3 seconds:
Code: Select all
void Update () {
if ( Mathf.Repeat( Time.time, 1f) > 0.5f) myShip.prime_Target = myTargetOne;
else myShip.prime_Target = myTargetTwo;
if ( Time.time > 3f && Time.time < 3.05f) myShip.prime_Target = null;
}
- Attachments
-
- Sample.rar
- (8.71 KiB) Downloaded 368 times
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [Unity] Binding to the nested properties.
Thing is that in order to make it work, you have to assign 'non-null' value to corresponding property before calling 'ContentControl.SetContent' , otherwise it won't show the property in GUI.
Both issues have been solved in 1.1.9 version.Eventually setting reference property value to null at any pont in time breaks the binding. Thus the following wouldn't work after 3 seconds
I tried your sample and is working fine in any scenario you displayed.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests