UE4
Topic Author
Posts: 62
Joined: 29 Dec 2017, 06:32

How binding a element of TArray?

12 Mar 2018, 03:04

I want to binding to TArray[0], so is there a way to get TArray[0], I find a class NoesisArrayWrapper, but in Private directory. may be I need a fucntion such as NoesisCreateTArrayForComponent?
<Button Content="{Binding SpellList, Converter={StaticResource SpellIndexConverter}, ConverterParameter=0}" Width="236.5" Height="100" Canvas.Left="345" Canvas.Top="529.5">
                </Button>
 
bool SpellIndexConverter::TryConvert(BaseComponent* value, const Type* targetType, BaseComponent* parameter, Ptr<BaseComponent>& result)
{
	int Idx = Boxing::Unbox<int>(parameter);
	//UObject* Array = NoesisCreateUObjectForComponent(value);
	/*NoesisArrayWrapper* Array = NsDynamicCast<NoesisArrayWrapper>(value);
	if (Array)
	{
	return Array->NativeGet(Idx);
	}*/
	return false;
}
 
User avatar
hcpizzi
Site Admin
Posts: 236
Joined: 09 Feb 2012, 12:40

Re: How binding a element of TArray?

12 Mar 2018, 23:21

Hi,

You shouldn't need to access the NoesisArrayWrapper class. It implements the IList interface. You should be able to do something like this:
bool SpellIndexConverter::TryConvert(BaseComponent* value, const Type* targetType, BaseComponent* parameter, Ptr<BaseComponent>& result)
{
	int Idx = Boxing::Unbox<int>(parameter);
	IList* List = NsDynamicCast<IList>(value);
	if (List && Idx >= 0 && Idx < (int)List->Count() )
	{
		result.Reset(List->Get(Idx));
		return true;
	}
	return false;
}
 
UE4
Topic Author
Posts: 62
Joined: 29 Dec 2017, 06:32

Re: How binding a element of TArray?

13 Mar 2018, 13:01

seems can not directly pass int 0 to ConverterParameter, the result of unbox is not a valid value.
And, how to binding the elememnt's member?
<Button Name="{Binding SpellList[0].DisplayName}"/>

unbox it to IList, may be hard to convert to UStruct?
 
User avatar
hcpizzi
Site Admin
Posts: 236
Joined: 09 Feb 2012, 12:40

Re: How binding a element of TArray?

15 Mar 2018, 14:10

Hi,

You can actually make that 0 to be parsed as an integer, in which case you would get a boxed integer, and there could be ways to get the UStruct from the IList.

But before we get into that, is <Button Content="{Binding SpellList[0].DisplayName}"/> what you're trying to do? Accessing element 0? Because that syntax you wrote should work, and you shouldn't have to write your own converter, and the Binding should take care of everything.
 
UE4
Topic Author
Posts: 62
Joined: 29 Dec 2017, 06:32

Re: How binding a element of TArray?

16 Mar 2018, 02:32

Hi,

You can actually make that 0 to be parsed as an integer, in which case you would get a boxed integer, and there could be ways to get the UStruct from the IList.

But before we get into that, is <Button Content="{Binding SpellList[0].DisplayName}"/> what you're trying to do? Accessing element 0? Because that syntax you wrote should work, and you shouldn't have to write your own converter, and the Binding should take care of everything.
that's what I need. So powerful
 
User avatar
jsantos
Site Admin
Posts: 2907
Joined: 20 Jan 2012, 17:18
Contact:

Re: How binding a element of TArray?

16 Mar 2018, 10:30

Thanks! Marking this as solved.

Who is online

Users browsing this forum: No registered users and 0 guests