[英]What is the code-behind equivalence of XAML <DataGrid Name="myDataGrid"/>?
我是否可以通過編程方式添加 WPF 項目,而無需手動干預 XAML? 請幫我一把。
后面的代碼中沒有“等價表達式”。 通過命名您的數據網格,您正在 class 上創建一個屬性,該屬性可以在您的代碼隱藏和 elsewehere 中訪問。
學習 xaml 標記是 wpf 開發的必要步驟,但是是的,wpf 應用程序可以純粹在 Z240AA2CEC4B89C56F3BEE5 中編寫
public class MainWindow : Window
{
DataGrid myDataGrid;
public MainWindow()
{
InitializeComponent();
var root = new Grid();
myDataGrid = new DataGrid();
var items = new List<DgItem> { new DgItem { Name = "A" } };
myDataGrid.ItemsSource = items;
root.Children.Add(myDataGrid);
this.Content = root;
}
}
public class DgItem
{
public string Name { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.