,你可以通过以下步骤实现:
<Window x:Class="YourNamespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Controls:DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
<!-- Define your DataGrid columns here -->
</Controls:DataGrid>
</Grid>
</Window>
public partial class MainWindow : Window
{
public ObservableCollection<Item> Items { get; set; }
public MainWindow()
{
InitializeComponent();
Items = new ObservableCollection<Item>();
// Add some sample data
Items.Add(new Item { Name = "Item 1", Price = 10 });
Items.Add(new Item { Name = "Item 2", Price = 20 });
// Set the ItemsSource property
dataGrid.ItemsSource = Items;
}
}
public class Item
{
public string Name { get; set; }
public double Price { get; set; }
}
<Controls:DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
<Controls:DataGrid.Columns>
<Controls:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<Controls:DataGridTextColumn Header="Price" Binding="{Binding Price}" />
</Controls:DataGrid.Columns>
</Controls:DataGrid>
这将在DataGrid中创建两列,分别显示"Name"和"Price"属性的值。
至于推荐的腾讯云相关产品,我们建议你参考腾讯云的官方文档和开发者文档,以获得更详细的信息。这些文档将提供有关腾讯云云计算产品的概念、分类、优势、应用场景以及相关产品的介绍和链接地址。
领取专属 10元无门槛券
手把手带您无忧上云