我在哪里可以在docs.microsoft.com的页面中找到代码示例? [英] Where can I find the code samples in a page at docs.microsoft.com?

查看:117
本文介绍了我在哪里可以在docs.microsoft.com的页面中找到代码示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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



https://docs.microsoft .com / 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自己读取数据。


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


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


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


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


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


I use .net/c#/wpf to develop some applications, and often I need to test the examples in a document web page at docs.microsoft.com 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:

https://docs.microsoft.com/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;

}

The GetData() 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.

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

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

https://gallery.technet.microsoft.com/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的页面中找到代码示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆