DataTemplateSelector in Unity Version
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:
And here is my DataTemplateSelector class:
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:
Code: Select all
<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>
Code: Select all
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...
}
}
}
-
-
sfernandez
Site Admin
- Posts: 3200
- Joined:
Re: DataTemplateSelector in Unity Version
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:
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:
Code: Select all
<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>
Re: DataTemplateSelector in Unity Version
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.
Re: DataTemplateSelector in Unity Version
We have created an internal ticket for this feature (low priority). If you want to track it, please, file a bug.
Thanks!
Thanks!
Re: DataTemplateSelector in Unity Version
Has this been implemented yet? I didn't see anything in Mantis for it.
-
-
sfernandez
Site Admin
- Posts: 3200
- Joined:
Re: DataTemplateSelector in Unity Version
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.
Re: DataTemplateSelector in Unity Version
Hi sfernandez,
I couldn't find anything in the Bugtracker or in the release notes about this. Is the DataTemplateSelector available for Unity now?
I couldn't find anything in the Bugtracker or in the release notes about this. Is the DataTemplateSelector available for Unity now?
-
-
sfernandez
Site Admin
- Posts: 3200
- Joined:
Re: DataTemplateSelector in Unity Version
Hi Danilo, the DataTemplateSelector is supported since very long time ago (probably 1.2 version).
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 16 guests