Page 1 of 1

How binding a element of TArray?

Posted: 12 Mar 2018, 03:04
by UE4
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;
}

Re: How binding a element of TArray?

Posted: 12 Mar 2018, 23:21
by hcpizzi
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;
}

Re: How binding a element of TArray?

Posted: 13 Mar 2018, 13:01
by UE4
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?

Re: How binding a element of TArray?

Posted: 15 Mar 2018, 14:10
by hcpizzi
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.

Re: How binding a element of TArray?

Posted: 16 Mar 2018, 02:32
by UE4
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

Re: How binding a element of TArray?

Posted: 16 Mar 2018, 10:30
by jsantos
Thanks! Marking this as solved.