Soheil Ghahremani
Soheil Ghahremani

Reputation: 1135

Implement a list that acts like combo box in windows phone

i want to implement a list of item that when user taps on a item it acts like a combo box and show details of selected item here is image of what i want. is it possible to implement this with listbox?

item list

Upvotes: 0

Views: 92

Answers (1)

Maulik Shah
Maulik Shah

Reputation: 673

XAML

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0">
        <StackPanel>
            <StackPanel >
                <Grid x:Name="itemgrid" Height="100" Background="Gray" Tap="itemgrid_Tap">
                    <TextBlock x:Name="itemtext" Text="˄" HorizontalAlignment="Left" Margin="50,0" FontSize="45" FontWeight="Bold" VerticalAlignment="Center"/>
                    <TextBlock Text="Item" HorizontalAlignment="Right" Margin="100,0" FontSize="35" VerticalAlignment="Center"/>
                </Grid>
                <ListBox Background="Green" x:Name="list" Visibility="Collapsed">
                    <ListBoxItem>
                        <TextBlock Text="Item1"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Text="Item2"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Text="Item3"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Text="Item4"/>
                    </ListBoxItem>
                </ListBox>
            </StackPanel>
            <StackPanel>
                <!--add same other-->
            </StackPanel>
            <StackPanel>
                <!--add same other-->
            </StackPanel>
        </StackPanel>
    </Grid>

C# :

bool isfirstitem = true;
    public MainPage()
    {
        InitializeComponent();
    }

    private void itemgrid_Tap(object sender, GestureEventArgs e)
    {
        if (isfirstitem)
        {
            itemtext.Text = "˅";
            list.Visibility = Visibility.Visible;
        }
        else
        {
            itemtext.Text = "˄";
            list.Visibility = Visibility.Collapsed;
        }

        isfirstitem=!isfirstitem;

    }

Upvotes: 1

Related Questions