ListView 控件是 Windows Forms 中的一个常用控件,用于显示和操作数据列表
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="MainWindow" Height="350" Width="525">
<Grid>
<wf:WindowsFormsHost Name="windowsFormsHost"/>
</Grid>
</Window>
using System.Windows;
using System.Windows.Forms;
namespace WpfApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ListView listView = new ListView();
listView.View = View.Details;
listView.Columns.Add("Column 1", 100);
listView.Columns.Add("Column 2", 100);
windowsFormsHost.Child = listView;
}
}
}
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid Name="dataGrid"/>
</Grid>
</Window>
using System.Collections.Generic;
using System.Windows;
namespace WpfApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<Item> items = new List<Item>
{
new Item { Column1 = "Item 1", Column2 = "Value 1" },
new Item { Column1 = "Item 2", Column2 = "Value 2" },
};
dataGrid.ItemsSource = items;
}
}
public class Item
{
public string Column1 { get; set; }
public string Column2 { get; set; }
}
}
这些方法可以帮助你在 WPF 应用程序中集成 ListView 控件或使用替代方案。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。