User avatar
jinfox
Topic Author
Posts: 69
Joined: 06 Apr 2019, 00:11

Binding a Custom control with Array type Dependency Property

17 Sep 2024, 11:23

Hello everyone,

I am currently creating a custom control that has as a Dependency property a list of string.
In c#, I would just have an
 ObservableCollection<string>
but in c++ this seems to be more complicated (I tried TArray<Noesis::String> but it didn't like it).
Taking example of other things being done in the engine I tried to create a String collection the following way :
typedef BoxedFreezableCollection<String> StringCollection;
And it works for my usecase (the property is read only so populated inside the custom control code so doesn't need to be bound).
But, for testing purposes, I would like to make it not read only and be able to Bind it directly to be able to Unit test the control.
however trying to bind the following way
<!-- With StringCollection being a DependencyProperty of type StringCollection (seen above)
And StringArray being a TArray<String>  -->
<MyCustomControl TheStringCollection="{Binding SomeViewModel.StringArray}"/> 
This code works in the Blend solution because I was able to have the property being an Observable Collection but in c++, Noesis doesn't know how to translate a TArray<FString> to my StringCollection type (which is logical).

I was curious to know if my approach was the correct one or if there was a way to make it all work without using a converter on that binding.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Binding a Custom control with Array type Dependency Property

17 Sep 2024, 21:08

If you want to bind an Unreal TArray (wich is wrapped as an IList to Noesis), you'll have to expose the property as a simple "object" (BaseComponent), same as ItemsSource property is defined by ItemsControl:
data->RegisterProperty<Ptr<BaseComponent>>(ItemsSourceProperty, "ItemsSource",
        FrameworkPropertyMetadata::Create(Ptr<BaseComponent>()));
You can add a ValidateValue callback to check if the value is an IList just in case.

Who is online

Users browsing this forum: No registered users and 4 guests