greenman
Topic Author
Posts: 2
Joined: 19 Feb 2014, 20:49

DataTemplateSelector in Unity Version

17 Mar 2014, 19:13

With the Unity version of Noesis GUI, is it possible to use a DataTemplateSelector, or is this not supported?

I have a ListBox with the ItemsSource property bound to a collection. When I set the ItemTemplate to a DataTemplate, everything works as expected. However, I want to choose which DataTemplate to use based on some custom logic with a DataTemplateSelector. I created a class which derives from DataTemplateSelector and overrode the SelectTemplate function, but it looks like that function is never being called. Is this not available in the Unity version of Noesis GUI? If not, are there plans to add it?

Here is my .xaml file:
<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:myproject="clr-namespace:MyProject"
	x:Class="MyProject.SettingsMenuControl">

	<UserControl.Resources>
		<myproject:SettingsMenuDataTemplateSelector x:Key="DataTemplateSelector"></myproject:SettingsMenuDataTemplateSelector>
		
		<DataTemplate x:Key="MenuItemStringTemplate">
			<Grid Width="200" Height="100">
				<Viewbox>
					<TextBlock Text="{Binding Name}"></TextBlock>
				</Viewbox>
			</Grid>
		</DataTemplate>
	</UserControl.Resources>

	<Grid x:Name="SettingsMenuGrid" Width="200" Background="#80000000">
		<ListBox ItemTemplateSelector="{StaticResource DataTemplateSelector}" ItemsSource="{Binding MenuItemCollection}">
		</ListBox>
	</Grid>
</UserControl>
And here is my DataTemplateSelector class:
using UnityEngine;
using System.Collections;
using Noesis;

namespace MyProject
{
	[Extended]
	public class SettingsMenuDataTemplateSelector : DataTemplateSelector
	{
		public override DataTemplate SelectTemplate(BaseComponent item, DependencyObject container)
		{
			// Choose DataTemplate here...
		}
	}
}
 
User avatar
sfernandez
Site Admin
Posts: 3008
Joined: 22 Dec 2011, 19:20

Re: DataTemplateSelector in Unity Version

18 Mar 2014, 10:55

Hi,

ItemTemplateSelector is not supported yet, even for native NoesisGUI.

Maybe you can work something out using data bindings to hide/show some parts of the item template, for example:
<DataTemplate>
    <Grid>
        <Border x:Name="BlueItem" Background="Blue" Visibility="{Binding BlueItemVisibility}"/>
            <TextBlock Text="{Binding ItemName}" Foreground="Cyan"/>
        </Border>
        <Border x:Name="RedItem" Background="Red" Visibility="{Binding RedItemVisibility}">
            <TextBlock Text="{Binding ItemName}" Foreground="Pink"/>
        </Border>
    </Grid>
</DataTemplate>
 
greenman
Topic Author
Posts: 2
Joined: 19 Feb 2014, 20:49

Re: DataTemplateSelector in Unity Version

19 Mar 2014, 20:51

Thanks for the quick response. Using data bindings to hide/show parts of the item template is a good solution. I tried it out and it worked for my purposes.
 
User avatar
jsantos
Site Admin
Posts: 3939
Joined: 20 Jan 2012, 17:18
Contact:

Re: DataTemplateSelector in Unity Version

19 Mar 2014, 22:26

We have created an internal ticket for this feature (low priority). If you want to track it, please, file a bug.

Thanks!
 
jgraham
Posts: 6
Joined: 24 Sep 2014, 21:08

Re: DataTemplateSelector in Unity Version

24 Sep 2014, 22:49

Has this been implemented yet? I didn't see anything in Mantis for it.
 
User avatar
sfernandez
Site Admin
Posts: 3008
Joined: 22 Dec 2011, 19:20

Re: DataTemplateSelector in Unity Version

25 Sep 2014, 21:50

No, it is not yet available for Unity. We recently add support for DataTemplateSelectors in the native side, so they will arrive to Unity soon.
 
Danilo
Posts: 7
Joined: 25 Nov 2021, 14:36

Re: DataTemplateSelector in Unity Version

30 Mar 2022, 10:08

Hi sfernandez,

I couldn't find anything in the Bugtracker or in the release notes about this. Is the DataTemplateSelector available for Unity now?
 
User avatar
sfernandez
Site Admin
Posts: 3008
Joined: 22 Dec 2011, 19:20

Re: DataTemplateSelector in Unity Version

31 Mar 2022, 08:14

Hi Danilo, the DataTemplateSelector is supported since very long time ago (probably 1.2 version).

Who is online

Users browsing this forum: Bing [Bot] and 10 guests