[SOLVED] ComboBox

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
hamej
Posts: 37
Joined: Thu Oct 01, 2015 8:41 am

[SOLVED] ComboBox

Postby hamej » Sat Apr 02, 2016 2:10 am

Since set of ComboBox.ItemsSource is not currently supported I try this:

public static void FillComboBox(ComboBox cb, ObservableCollection<PersonListEntry> Items)
{
cb.Items.Clear();

foreach (var v in Items)
cb.Items.Add(v);
}

but gets the error: ItemTemplate is not supported yet in ComboBox. Does this mean, that I can't fill a ComboBox with anything but simple values (string, int)?

JS-Support
Site Admin
Posts: 789
Joined: Tue Apr 08, 2014 3:42 pm

Re: ComboBox

Postby JS-Support » Mon Apr 04, 2016 8:59 am

Hi,

ComboBox.ItemsSource is supposed to work fine.

Here is an example of use:

Code: Select all

<StackPanel>
    <ComboBox x:Name="ComboBox1" DisplayMemberPath="Name"/>
    <TextBlock Text="Selected planet radius:"/>
    <TextBlock Text="{Binding ElementName=ComboBox1, Path=SelectedItem.Radius}"/>
</StackPanel>


Code: Select all

class Planet
{
    public string Name { get; set; }
    public string Radius { get; set; }
    public string RotationPeriod { get; set; }
    public string OrbitalPeriod { get; set; }
    public string ImagePath { get; set; }
}


Code: Select all

var planets = new ObservableCollection<Planet>()
            {
               new Planet() { Name = "Mercury", Radius = "2,400 km", RotationPeriod = "59 days", OrbitalPeriod = "3 months", ImagePath = "ms-appx:/Planets/Mercury.png" },
               new Planet() { Name = "Venus", Radius = "6,100 km", RotationPeriod = "243 days", OrbitalPeriod = "7 months", ImagePath = "ms-appx:/Planets/Venus.png" },
               new Planet() { Name = "Earth", Radius = "6,400 km", RotationPeriod = "1 day", OrbitalPeriod = "1 year", ImagePath = "ms-appx:/Planets/Earth.png" },
               new Planet() { Name = "Mars", Radius = "3,400 km", RotationPeriod = "1 day, 37 min", OrbitalPeriod = "2 years", ImagePath = "ms-appx:/Planets/Mars.png" },
               new Planet() { Name = "Jupiter", Radius = "71,500 km", RotationPeriod = "1 day, 10 hrs", OrbitalPeriod = "12 years", ImagePath = "ms-appx:/Planets/Jupiter.png" },
               new Planet() { Name = "Saturn", Radius = "60,300 km", RotationPeriod = "1 day, 11 hrs", OrbitalPeriod = "30 years", ImagePath = "ms-appx:/Planets/Saturn.png" },
               new Planet() { Name = "Uranus", Radius = "25,600 km", RotationPeriod = "1 day, 17 hrs", OrbitalPeriod = "84 years", ImagePath = "ms-appx:/Planets/Uranus.png" },
               new Planet() { Name = "Neptune", Radius = "24,800 km", RotationPeriod = "1 day, 16 hrs", OrbitalPeriod = "165 years", ImagePath = "ms-appx:/Planets/Neptune.png" },
            };
            ComboBox1.ItemsSource = planets;


In the current Beta 7.2, the combo box uses the native HTML5 control, so it can only display simple values. However, the "ItemsSource" collection can contain complex objects. You can tell the ComboBox which value to display by setting the "DisplayMemberPath" property of the ComboBox, as shown in the example above.

Regards,
JS-Support

hamej
Posts: 37
Joined: Thu Oct 01, 2015 8:41 am

Re: ComboBox

Postby hamej » Thu Apr 07, 2016 6:24 am

OK. I have studied the planet showcase. I will try to get the functionality, I want, by using an ItemsControl wrapped in a ScrollViewer. But I suppose, you will have the ComboBox with the same functionality as i Silverlight, when your product is fnished?

JS-Support
Site Admin
Posts: 789
Joined: Tue Apr 08, 2014 3:42 pm

Re: ComboBox

Postby JS-Support » Sat Mar 04, 2017 8:07 pm

Hi,

To get the same functionality as in Silverlight, please use the non-native-html ComboBox. To do so, use this code:

Code: Select all

<ComboBox UseNativeComboBox="False" />


Thanks.
Regards,
JS-Support


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 1 guest

 

 

cron