C4ustic
Topic Author
Posts: 8
Joined: 03 Sep 2017, 03:02

DataTemplate with DataType sys:Single or sys:String is not used.

04 Sep 2018, 02:04

I have a ListBox with different items, when the item is a string or float I want to use a specific DataTemplate. Using DataType="{x:Type sys:String}" where xmlns:sys="clr-namespace:System;assembly=mscorlib" works when I run in windows but not under NoesisGUI. I have another template for when the item is a vector DataType="{x:Type local:UiVector3}" and this type works correctly and my DataTemplate for it is used.

Here is my xaml code, the NsPropertyTemplate is usesd because I set it as ItemTemplate="{DynamicResource NsPropertyTemplate}" The UiVector3 is correctly identified and that template is used but for a string I get the standard output and my template is not used.
	
	<DataTemplate DataType="{x:Type sys:String}">
		<StackPanel Orientation="Vertical">
			<TextBox Text="{Binding Path=Content, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
		</StackPanel>
	</DataTemplate>

	<DataTemplate DataType="{x:Type local:UiVector3}">
		<StackPanel Orientation="Horizontal">
			<TextBox Width="64" Text="{Binding x, UpdateSourceTrigger=PropertyChanged}"/>
			<TextBox Width="64" Text="{Binding y, UpdateSourceTrigger=PropertyChanged}"/>
			<TextBox Width="64" Text="{Binding z, UpdateSourceTrigger=PropertyChanged}"/>
		</StackPanel>
	</DataTemplate>

	<DataTemplate x:Key="NsPropertyTemplate">
		<StackPanel Orientation="Horizontal">
			<TextBlock Text="{Binding Path=Name}"/>
			<ContentPresenter Content="{Binding Path=Value, Mode=TwoWay}"/>
		</StackPanel>
	</DataTemplate>
Side note:
I can't get UnityEngine:Vector3 to work at all, get an internal error. I have a workaround for this where I simply change them to a locally defined UiVector3 in the code behind setter.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: DataTemplate with DataType sys:Single or sys:String is not used.

05 Sep 2018, 11:06

This looks like a bug in the DataTemplate data type resolution, could you please report it in our bugtracker? Thanks.

What error are you getting when directly using UnrealEngine.Vector3 class? Is it a crash of Unity Editor?
One thing to notice is that UnrealEngine.Vector3 exposes x,y,z through fields instead of properties, so you won't be able to bind to them, Noesis can only bind to public properties. This means you won't see the values, but nothing should crash.

Maybe you can use a DataTemplateSelector until we fix the automatic data type resolution.

Who is online

Users browsing this forum: No registered users and 1 guest