Piya
Piya

Reputation: 93

How to show list of items on button click?

I am developing windows phone app.. I am taking 1 button and on click of that button the dropdown list of clothes should come.. how to code for this?

Problem: How to take this list on button click

Upvotes: 0

Views: 670

Answers (2)

Jaihind
Jaihind

Reputation: 2778

Your xaml should be :

<Button x:Name="BtnShowCloth"  Content="showCloth" Margin="10,5" Click="BtnAddProduct_Click"/>    
<toolkit:ListPicker    ExpansionMode="FullScreenOnly"   x:Name="ClothListPicker"  Visibilty="Collapsed"   Margin="0,0,0,10"  Height="100" >
  <toolkit:ListPicker.ItemTemplate>
    <DataTemplate>
      <TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}"/>
    </DataTemplate>
  </toolkit:ListPicker.ItemTemplate>
  <toolkit:ListPicker.FullModeItemTemplate>
    <DataTemplate>
      <TextBlock Style="{StaticResource AppTextBlockStyle}"  Text="{Binding}"  Margin="2,10,0,0" FontSize="31"/>
    </DataTemplate>
  </toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>

//Another way use ListBox Control

<ListBox  Grid.Row="1" Name="ListBoxCloth" Height="50">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}"  Text="{Binding}"  Margin="2,10,0,0" FontSize="31"/>
</DataTemplate>
<ListBox.ItemTemplate>
</ListBox>

Code Behind of button click fill list of cloth names. In windows phone no dropdown list exist, you should use longlistselector instead of dropdown

 private void BtnAddProduct_Click(object sender, RoutedEventArgs e)
    {
        List<string> clothNameList = new List<string>();
        clothNameList .Add("a");
        clothNameList .Add("b");
        clothNameList .Add("c");
        clothNameList .Add("d");
        clothNameList .Add("e");
        //ClothListPicker.ItemsSource = clothNameList;
       // ClothListPicker.Visibility = Visibility.visible;
        ListBoxCloth.ItemsSource = clothNameList;
        ListBoxCloth.Height = 400;
    }

Upvotes: 1

nkchandra
nkchandra

Reputation: 5557

This is very broad question, infact does not fall in SO standards of Questions.

You should research and try something and ask only if you got stuck somewhere or if your method fails.

And to your question, it needs clarification on many things like

  • What is the format of your clothes data
  • Are you getting it from a web service or a local db or some other resource
  • Is it a single List or a groups of items etc

Hence, it becomes hard to answer. Please keep these things in mind, next time when asking questions.

Based on your comment:

You should split your task into multiple small tasks

  • First thing, learn how to fetch the data from your db
  • Converting that data into List of objects
  • Creating your UI for the data
  • Bind the data to the UI in your Button_Click event handler

Happy coding !!

Upvotes: 1

Related Questions