- arbonix-allison
- Posts: 1
- Joined:
Bindings to dynamic properties on a DynamicObject failing in Noesis, but not Windows WPF
I am creating Binding objects in C#, like so:
Now, if `dataContext` is a plain object with a property on it called `ButtonPressCount`, we're all good! But, if it's a DynamicObject that resolves `ButtonPressCount` via `TryGetMember`, it breaks and says that `ButtonPressCount` doesn't exist.
It works fine in Blend.
Thanks in advance!
Code: Select all
TextBlock textBlock = new TextBlock();
textBlock.DataContext = dataContext;
Binding binding = new Binding("ButtonPressCount")
{
StringFormat = "Button press count, read directly off parent object (no proxy): {0}"
};
textBlock.SetBinding(TextBlock.TextProperty, binding);
It works fine in Blend.
Thanks in advance!
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Bindings to dynamic properties on a DynamicObject failing in Noesis, but not Windows WPF
Hello,
We haven't ever tried using DynamicObjects in Noesis. But in our current implementation, when a C# object is passed to our library we generate a Type representation in the native side by using C# reflection (Type.GetProperties). So only the properties that are defined at that point would be available in bindings.
For this DynamicObject to work I guess we will need some sort of find property fallback, that can check if a new property was added after native Type creation. We need to think about this, could you please report it in our bugtracker?
An alternative solution is to use an indexer (like a Dictionary) with string keys (which will be the property names):
Could that work for you?
We haven't ever tried using DynamicObjects in Noesis. But in our current implementation, when a C# object is passed to our library we generate a Type representation in the native side by using C# reflection (Type.GetProperties). So only the properties that are defined at that point would be available in bindings.
For this DynamicObject to work I guess we will need some sort of find property fallback, that can check if a new property was added after native Type creation. We need to think about this, could you please report it in our bugtracker?
An alternative solution is to use an indexer (like a Dictionary) with string keys (which will be the property names):
Code: Select all
public class MyDynamicObject
{
private Dictionary<string, object> _values = new();
public object this[string s]
{
get { return _values.TryGetValue(s, out val) ? val : null; }
set { _values[s] = value; }
}
}
Code: Select all
<TextBlock Text="{Binding SomeDynamicObject[ButtonPressCount]}"/>
Who is online
Users browsing this forum: Bing [Bot] and 4 guests