我想实现一个项目列表,当用户点击某个项目时,它就像一个组合框并显示所选项目的详细信息 这是我想要的形象。可以用listbox实现吗?
答案 0 :(得分:1)
<强> 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;
}