I tried the following scenario and worked as expected:
- Created a new scene in Unity
- Selected the Main Camera object
- Added a new NoesisGUIPanel component
- Attached the following xaml to the Xaml property:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ComboBox x:Name="cb" Template="{DynamicResource NoesisComboBoxTemplate}" Width="200" VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
- Attached Assets/NoesisGUI/Themes/NoesisStyle to the Style property
- Added a new C# script to the Main Camera with the following code:
using UnityEngine;
using System.Collections;
using Noesis;
[Extended]
public class DataItem : BaseComponent
{
public string DisplayName { get; set; }
}
public class Test : MonoBehaviour
{
void Start()
{
var gui = GetComponent<NoesisGUIPanel>();
var root = gui.GetRoot<Grid>();
var cb = root.FindName<ComboBox>("cb");
cb.SelectionChanged += this.OnSelectionChanged;
Collection items = new Collection();
items.Add(new DataItem { DisplayName = "John" });
items.Add(new DataItem { DisplayName = "Peter" });
items.Add(new DataItem { DisplayName = "Mike" });
items.Add(new DataItem { DisplayName = "Andrew" });
items.Add(new DataItem { DisplayName = "Robert" });
cb.SetItemsSource(items);
}
void OnSelectionChanged(BaseComponent sender, SelectionChangedEventArgs e)
{
Debug.Log("Selection changed");
}
}
When I click play, a ComboBox is rendered in the center of the Game View. It can be expanded, and any of the items can be selected calling the corresponding SelectionChanged event.
Is this working for you?
What is your scene configured?