简体   繁体   English

在Windows Phone中使用ListBox出现问题

[英]Trouble using ListBox in windows phone

Xaml Xaml

<ListBox x:Name="List" Margin="8,8,8,8">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical" Width="Auto" Height="300">
                <TextBlock x:Name="tbName" Width="Auto" FontSize="22" FontWeight="Bold" Text="{Binding Name}" />
                <TextBlock x:Name="tbEmail" Width="Auto" FontSize="22" Height="Auto" Text="{Binding Amount}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <Button Content="Button" Height="89" Click="Button_Click_2" Width="138"/>
</ListBox>

C# C#

foreach (var item in Expense)
{
    Display data = new Display();
    data.Name = item.Account_Name;
    data.Amount = item.Total;
    this.List.Items.Add(data);
}

While the above code executes in windows phone, i get a list box with name and amount in two different lines. 虽然上面的代码在Windows Phone中执行,但我在两个不同的行中得到了一个名称和金额列表框。 What should i do, to make them display in same line,(name in left and amount in right)?? 我应该怎么做,以使它们显示在同一行中(名称在左边,金额在右边)?

Stackpanel needs the Horizontal orientation Stackpanel需要水平方向

<StackPanel Orientation="Horizontal" Width="Auto" Height="300">
    <TextBlock x:Name="tbName" Width="Auto" FontSize="22" FontWeight="Bold" Text="{Binding Name}" />
    <TextBlock x:Name="tbEmail" Width="Auto" FontSize="22" Height="Auto" Text="{Binding Amount}"/>
</StackPanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM