【发布时间】:2011-10-16 08:02:07
【问题描述】:
这可能是一个愚蠢的问题,但我坚持这样做:(。我有一个网格和 3 列。我在这 3 列中的每一列中都有一个文本框和一个列表框,如图所示:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"></ColumnDefinition>
<ColumnDefinition Width="380"></ColumnDefinition>
<ColumnDefinition Width="146"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0">
<TextBox Text="File Name" Height="30"></TextBox>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0">
<TextBox Text="File Path" Height="30"></TextBox>
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="0">
<TextBox Text="File Size" Height="30"></TextBox>
</StackPanel>
<StackPanel Grid.Column="0">
<ListBox Name="listbox_name" Margin="1,30" Height="276" />
</StackPanel>
<StackPanel Grid.Column="1">
<ListBox Name="listbox_path" Margin="1,30" Height="276" />
</StackPanel>
<StackPanel Grid.Column="2">
<ListBox Name="listbox_size" Margin="1,30" Height="276" />
</StackPanel>
及其背后的代码:
public Window1()
{
InitializeComponent();
list.Add("D:\\a\\hy");
list.Add("D:\\a\\hy1");
list.Sort();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
listbox_name.ItemsSource = list;
grid1.Visibility = Visibility.Hidden;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
grid1.Visibility = Visibility.Visible;
}
但是在单击按钮时,我看不到列表框,并显示了列表。请指导我哪里出错了。谢谢!
【问题讨论】:
-
为什么要使用这么多堆栈面板来显示标题...只需使用 ListView 并在其中使用 GridView 并制作 GridView 列...。
-
嗨,@adcool2007 我是新手,所以我不知道该怎么做。也会试试你的方法谢谢!
标签: c# wpf listbox grid stackpanel