Binding a Custom control with Array type Dependency Property
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 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 :
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
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.
I am currently creating a custom control that has as a Dependency property a list of string.
In c#, I would just have an
Code: Select all
ObservableCollection<string>Taking example of other things being done in the engine I tried to create a String collection the following way :
Code: Select all
typedef BoxedFreezableCollection<String> StringCollection;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
Code: Select all
<!-- With StringCollection being a DependencyProperty of type StringCollection (seen above)
And StringArray being a TArray<String> -->
<MyCustomControl TheStringCollection="{Binding SomeViewModel.StringArray}"/> 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.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Binding a Custom control with Array type Dependency Property
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:
You can add a ValidateValue callback to check if the value is an IList just in case.
Code: Select all
data->RegisterProperty<Ptr<BaseComponent>>(ItemsSourceProperty, "ItemsSource",
FrameworkPropertyMetadata::Create(Ptr<BaseComponent>()));Who is online
Users browsing this forum: No registered users and 4 guests