我在哪里可以在docs.microsoft.com的页面中找到代码示例?

编程入门 行业动态 更新时间:2024-10-24 14:20:03
本文介绍了我在哪里可以在docs.microsoft的页面中找到代码示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 / c#/ wpf来开发一些应用程序,我经常需要在visual studio的docs.microsoft上的文档网页中测试这些示例来学习事情深刻。例如,当我需要在WPF中学习DataGrid控件的属性时,我读了文档:

docs.microsoft / zh-cn / dotnet / api / system.windows.controls.datagrid?view = netframework-4.7.2#examples

在文档中,有一个代码片段:

public Window1() { InitializeComponent(); // GetData()从数据库中创建Customer数据集合 ObservableCollection< Customer> custdata = GetData (); //将DataGrid绑定到客户数据 DG1.DataContext = custdata ; }

GetData() 方法用于生成应用程序的数据。它未在文档中列出但我怎么能找到它的完整源代码呢?我不想浪费时间自己写一个实现。我在Github中搜索,但没找到。

解决方案

我不知道它会在哪里。

那里的代码显示了被广泛认为是不良做法的技术。

这一点:

DG1.DataContext = custdata;

那不是开始工作。

这是你需要设置的数据网格的ItemsSource但你真的应该使用MVVM和绑定。

MVVM isn这只是一个可选模式,它几乎是商业团队用来开发wpf应用程序的唯一模式。如果你的目标是在商业上进行wpf开发,你应该尽早学习。

我会使用实体框架和linq自己读取数据。

以下是一个人如何以这种方式工作的基本版本。

social.technet.microsoft/wiki/contents/articles/28209.wpf-entity-framework-mvvm-walk-through-1.aspx

此示例稍微复杂一点,因为它增加了验证:

gallery.technet.microsoft/scriptcenter/WPF-Entity-Framework-MVVM -78cdc204

我通常会为每个数据行设置自我跟踪视图模型,而不是直接使用实体对象......但这将是第3步,再次是另一个示例。

I use /c#/wpf to develop some applications, and often I need to test the examples in a document web page at docs.microsoft in visual studio to learn things deeply. For example, when I need to learn the properties of DataGrid control in WPF, I read the document:

docs.microsoft/en-us/dotnet/api/system.windows.controls.datagrid?view=netframework-4.7.2#examples

In the document, there is a code snippet:

public Window1() { InitializeComponent(); //GetData() creates a collection of Customer data from a database ObservableCollection<Customer> custdata = GetData(); //Bind the DataGrid to the customer data DG1.DataContext = custdata; }

TheGetData()method is used to generate the data of the application. It is not listed in the document directly. But how can I find it's full source code? I don't want to waste time to write an implemation myself. I searched in Github, but not found.

解决方案

I have no idea where that would be.

The code there shows techniques which are widely considered bad practice.

And this bit:

DG1.DataContext = custdata;

That's just not going to work.

It's the ItemsSource of a datagrid you'd need to set BUT you should really be using MVVM and binding.

MVVM isn't just an optional pattern, it's pretty much the ONLY pattern that commercial teams will use to develop wpf apps. You should learn it as early as possible if you aim to do wpf development commercially.

.

I'd use entity framework and linq to read the data myself.

And the following is a basic version of how one might work that way.

social.technet.microsoft/wiki/contents/articles/28209.wpf-entity-framework-mvvm-walk-through-1.aspx

This sample is a bit more sophisticated in that it adds validation:

gallery.technet.microsoft/scriptcenter/WPF-Entity-Framework-MVVM-78cdc204

I would usually have self tracking viewmodels for each of the data rows rather than using entity objects directly... but that would be step 3 and another sample again.

更多推荐

我在哪里可以在docs.microsoft.com的页面中找到代码示例?

本文发布于:2023-11-05 12:49:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   示例   代码   页面   中找到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!