简体   繁体   English

XAML 的代码隐藏等效项是什么<datagrid Name="myDataGrid" /> ?

[英]What is the code-behind equivalence of XAML <DataGrid Name="myDataGrid"/>?

Can I add WPF items programmatically without any manual interference with XAML?我是否可以通过编程方式添加 WPF 项目,而无需手动干预 XAML? Please give me a hand.请帮我一把。

There is no "equivalent expression" in code behind.后面的代码中没有“等价表达式”。 By naming your datagrid you are creating a property on your class that can be accessed in your code-behind and elsewehere.通过命名您的数据网格,您正在 class 上创建一个属性,该属性可以在您的代码隐藏和 elsewehere 中访问。

learning xaml markup is necessary step in wpf development, but yes, wpf app can be written purely in c#:学习 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM