markj
Topic Author
Posts: 4
Joined: 11 Jun 2014, 01:08

ComboBox functionality with a template equipped

09 Jul 2014, 03:46

If I have a ComboBox with a specified ItemsSource binding, and also equip a template such as the built-in NoesisComboBoxTemplate, the ComboBox seems to be missing some functionality. I can open/close the drop-down by clicking on the ComboBox button, but I can't select any of the items in the drop down. The mouse will highlight individual items, but clicking won't change the ComboBox selection or collapse the drop down. If I don't equip a template, then the combobox does select items and causes the SelectionChanged event.

Any ideas? I'm running in Unity 4.5.1f3.

Thanks,
Mark
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: ComboBox functionality with a template equipped

09 Jul 2014, 17:26

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?

Who is online

Users browsing this forum: No registered users and 1 guest