我可以描述发生的事情的唯一方法是使用图像,所以我希望这会出现,我认为我的问题出在 itemsource 中,因为我将它们放在列表框中并且电子邮件列表中没有空格,在 col1 中它显示名称,并在 col2 中显示电子邮件,但不在同一行上,所有内容都被向下推。
这是xaml
<Window x:Class="test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="492" Width="865" ResizeMode="CanMinimize">
<Grid>
<Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" IsEnabled="False" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,46,0,0" Name="textBox1" VerticalAlignment="Top" Width="180" />
<Label Content="Email" Height="28" HorizontalAlignment="Left" Margin="12,138,0,0" Name="label3" VerticalAlignment="Top" IsEnabled="False" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,172,0,0" Name="textBox3" VerticalAlignment="Top" Width="180" />
<Label Content="Website" Height="28" HorizontalAlignment="Left" Margin="12,75,0,0" Name="label4" VerticalAlignment="Top" IsEnabled="False" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="12,109,0,0" Name="textBox4" VerticalAlignment="Top" Width="180" />
<Calendar Height="170" HorizontalAlignment="Left" Margin="12,235,0,0" Name="calendar1" VerticalAlignment="Top" Width="180" />
<Label Content="Send Date" Height="28" HorizontalAlignment="Left" Margin="12,203,0,0" Name="label2" VerticalAlignment="Top" IsEnabled="False" />
<TabControl Height="391" HorizontalAlignment="Left" Margin="225,14,0,0" Name="tabControl1" VerticalAlignment="Top" Width="606">
<TabItem Header="My" Name="tabItem1" IsEnabled="True">
<Grid>
<ListView Height="359" ItemsSource="{Binding Tab1Collection}" HorizontalAlignment="Left" Name="listView1" VerticalAlignment="Top" Width="596">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding name1}" Header="Name" Width="150" />
<GridViewColumn DisplayMemberBinding="{Binding email1}" Header="Email" Width="255" />
<GridViewColumn DisplayMemberBinding="{Binding website1}" Header="Website" Width="200" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</TabItem>
<TabItem Header="Finished" Name="tabItem2" IsEnabled="true">
<Grid>
<ListView Height="359" HorizontalAlignment="Left" Name="listView2" VerticalAlignment="Top" Width="596">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="150" />
<GridViewColumn Header="Email" Width="150" />
<GridViewColumn Header="Website" Width="150" />
<GridViewColumn Header="Delivered On" Width="150" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</TabItem>
<TabItem Header="Results" Name="tabItem3" IsEnabled="False">
<Grid />
</TabItem>
<TabItem Header="Directory" Name="tabItem4" IsEnabled="true" IsSelected="True">
<Grid Height="362"></Grid>
</TabItem>
</TabControl>
<Button Content="Add Contact" Height="29" HorizontalAlignment="Left" Margin="97,411,0,0" Name="button1" VerticalAlignment="Top" Width="95" />
</Grid>
这是代码
private List<string> names = new List<string>();
private List<string> Emails = new List<string>();
public MainWindow()
{
InitializeComponent();
names.Add("test123");
names.Add("test123");
names.Add("test123");
names.Add("tst123");
names.Add("test123");
names.Add("tst123");
Emails.Add("test123@Gmail.com");
Emails.Add("test123@Gmail.com");
Emails.Add("test123@Gmail.com");
Emails.Add("test123@Gmail.com");
Emails.Add("test123@Gmail.com");
Emails.Add("test123@Gmail.com");
foreach(var n in names) {
listView1.Items.Add(new {name1 = n});
}
foreach(var e in Emails) {
listView1.Items.Add(new {email1 = e});
}
}
这是解释发生了什么的图像,一切都应该在同一行。