locked
How to bind a list names and its images on a combobox using a json string that i get from a web service? RRS feed

  • Question

  • I have this class that holds a list of string and i am supposed to bind my local images based on the string name e.g(Dropbox and dropbox icon OR skydrive and skydrive icon) inside a combobox.

     public class SupportedProviders
        {
            public List<string> Provider { get; set; }
        }

    example json string 

    {Provider:["Box","Dropbox","FileSystem","FTP","Google Drive","SFTP","SharePoint","SkyDrive","SMB"]}

    so how can i achieve this ;



    19karabo91

    Wednesday, October 2, 2013 7:47 AM

Answers

  • Hello 19karabo91,

    Try to make one another class with their property (string, imagepath). Get string form your supportedproviders class and get image path . Than make one collection object (ObservableCollection<Classname>) than bind to combobox. In combobox make that design like this :

     <ComboBox x:Name="cmbSTP" Margin="25,10,25,0" Background="White" MaxWidth="250">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel MaxWidth="250">
                                            <TextBlock  Text="{Binding FirstColumn}"/>
    <Image Source="{Binding SecondColumn}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>

    • Marked as answer by 19karabo91 Wednesday, October 2, 2013 8:45 AM
    Wednesday, October 2, 2013 8:37 AM

All replies

  • Hello 19karabo91,

    Try to make one another class with their property (string, imagepath). Get string form your supportedproviders class and get image path . Than make one collection object (ObservableCollection<Classname>) than bind to combobox. In combobox make that design like this :

     <ComboBox x:Name="cmbSTP" Margin="25,10,25,0" Background="White" MaxWidth="250">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel MaxWidth="250">
                                            <TextBlock  Text="{Binding FirstColumn}"/>
    <Image Source="{Binding SecondColumn}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>

    • Marked as answer by 19karabo91 Wednesday, October 2, 2013 8:45 AM
    Wednesday, October 2, 2013 8:37 AM
  • Wow i didn't think it would be that simple ,its just that i'm still new in xaml and c# , so what is the easiest way to get those string values and pass them to the new class i have to create ?

    Thanks Khant Nipun

     

    19karabo91

    Wednesday, October 2, 2013 8:50 AM
  • i have done exactly what you told me but when i run the app i can see the items in the combobox?  

    19karabo91

    Monday, October 7, 2013 12:38 PM