-
- landongrant
- Posts: 4
- Joined:
Issue driving component bindings with UObject / AActor
Hey all,
I've written a custom component that I'd like to reuse which I reference in my main xaml file like this:
Where MyObjects is an array of type that inherits from AActor.
Inside of the component xaml file I have something like this:
My intent here is to provide one of the entries in MyObjects as a reference to the DataRef of my component so that I can bind elements like visibility to properties of that object.
It works perfectly fine if I am explicitly setting the DataContext inside of the component to the Ancestor array entry directly like this:
Obviously this isn't scalable so I am wondering why I can't just pass it in like I was above.
Thinking maybe there is something wrong on the C++ side so I tried something like this:
But I guess this type of RegisterProperty only works with primitive data types? Maybe I am also misunderstanding...
Appreciate any help that can be given here!
I've written a custom component that I'd like to reuse which I reference in my main xaml file like this:
Code: Select all
<local:MyComponent x:Name="Component1" DataRef="{Binding MyObjects[2]}"/>Inside of the component xaml file I have something like this:
Code: Select all
<Grid x:Name="MyComponentGrid"
Width="700" Height="700"
DataContext="{Binding DataRef, RelativeSource={RelativeSource AncestorType=UserControl}}">
<Image x:Name="MyComponentImage"
Source="Images/sourceimg.png"
Visibility="{Binding bShouldShowImg,
Converter={StaticResource BoolToVisibilityConverter}}"/>
It works perfectly fine if I am explicitly setting the DataContext inside of the component to the Ancestor array entry directly like this:
Code: Select all
<Grid DataContext="{Binding DataContext.MyObjects[2], RelativeSource={RelativeSource AncestorType=UserControl, AncestorLevel=2}}">Obviously this isn't scalable so I am wondering why I can't just pass it in like I was above.
Thinking maybe there is something wrong on the C++ side so I tried something like this:
Code: Select all
NS_BEGIN_COLD_REGION
NS_IMPLEMENT_REFLECTION(NameSpace::MyComponent, "NameSpace.MyComponent")
{
auto* dd = NsMeta<DependencyData>(TypeOf<SelfClass>());
dd->RegisterProperty<AActor*>(
SeatDataProperty, "DataRef",
Noesis::PropertyMetadata::Create<AActor*>(nullptr));
}
NS_END_COLD_REGIONAppreciate any help that can be given here!
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Issue driving component bindings with UObject / AActor
Hi,
The issue comes from defining the Dependency Property as an AActor*, because that is interpreted as a number by Noesis and we cannot get any reflection information about it.
You should define the property as Ptr<BaseComponent> so we can wrap your Unreal object with one of our types that contains the reflection information about the Unreal type, so bindings can resolve the references to its properties.
Could you try that?
The issue comes from defining the Dependency Property as an AActor*, because that is interpreted as a number by Noesis and we cannot get any reflection information about it.
You should define the property as Ptr<BaseComponent> so we can wrap your Unreal object with one of our types that contains the reflection information about the Unreal type, so bindings can resolve the references to its properties.
Code: Select all
NS_IMPLEMENT_REFLECTION(NameSpace::MyComponent, "NameSpace.MyComponent")
{
auto* dd = NsMeta<DependencyData>(TypeOf<SelfClass>());
dd->RegisterProperty<Ptr<BaseComponent>>(
SeatDataProperty, "DataRef",
Noesis::PropertyMetadata::Create<Ptr<BaseComponent>>(Ptr<BaseComponent>(nullptr)));
}-
- landongrant
- Posts: 4
- Joined:
Re: Issue driving component bindings with UObject / AActor
Absolute legend!
Seems to be working on a very basic case now. I will spend some time to iterate further and will post an update later. Would appreciate if you could also review my implementation once it's ready to ensure I am on the right track.
Thank you for the quick response!
Seems to be working on a very basic case now. I will spend some time to iterate further and will post an update later. Would appreciate if you could also review my implementation once it's ready to ensure I am on the right track.
Thank you for the quick response!
Who is online
Users browsing this forum: No registered users and 4 guests