DataTemplateSelector in Unity Version
Posted: 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:
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...
}
}
}