更新时间:2023-09-21 13:15:40
好的.我实际上翻阅了那篇文章,只是为了表现出诚意,让您知道我真的很想帮助您.
Ok. I actually went thru that article, just to show good faith and let you know that I actually want to help you.
我得出以下结论:
您可以在不需要复杂逻辑的情况下使用设计器,但是我必须警告您以下缺点:
You can use the designer for such situations where you don't require complex logic, however I must warn you the following cons:
x:Name="categoryIdColumn"
和诸如 Margin="13,13,43,191"
之类的东西的 XAML,它们是从可维护性/可扩展性的角度来看真的很糟糕)CollectionViewSource
,这既是好事也是坏事.这是一件好事,因为它使 Design-DataGrid 中的时间数据
,但它也很糟糕,因为它会用大量不需要的东西使您的 XAML 膨胀,并引入不必要的
使事情复杂化.x:Name="categoryIdColumn"
and things like Margin="13,13,43,191"
which are really bad from a maintainabilty / scalability point of view)CollectionViewSource
, this is both a good thing and a bad thing. It's a good thing because it enables Design-Time Data
in the DataGrid, but it is also bad because it bloats your XAML with lots of unneeded things and introduces unnecessary <Window.Resources>
that complicate things up.现在,这是该 DataGrid 所需的非常少的 XAML,没有设计时数据支持:
Now, this is the very minimal XAML needed for that DataGrid, without Design-time data support:
<Window x:Class="MiscSamples.DesignTimeDataGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DesignTimeDataGrid">
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGridTextColumn Header="Category Id" Binding="{Binding CategoryId}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
</DataGrid>
</Window>
你看到了吗?实际上,键入该内容(在 Intellisense 的帮助下更是如此)比浏览属性窗口并手动设置这些属性要快.
You see? It's actually faster to type that (much more so with the help of Intellisense) than what it takes for you to browse the property window and set these properties manually.
我的建议是你要熟悉 XAML,而不是硬着头皮做事
要记住的另一个非常重要的方面是,一般来说,您不会在 WPF 中的代码隐藏中放置任何内容 因为不需要,因此该教程实际上违背了 WPF 做事方式,但没关系,因为它实际上是实体框架教程,而不是 WPF 教程.
Another very important aspect to keep in mind is that generally speaking, you don't put anything in code-behind in WPF because it's not needed, therefore that tutorial is actually going against the WPF Way of doing things, but that's Ok because it's actually an Entity Framework tutorial, not a WPF tutorial.
易于开发
您确实需要重新考虑所谓的易于开发".说到 UI 开发,我称之为易于开发"实际上能够用 UI 做我想做的事不必求助于涉及 P/Invoke(无论这意味着什么)和所有者绘制"类型的东西的糟糕程序代码实践.
You really need to reconsider what you call "ease of development". When it comes to UI development, I call "ease of development" to actually being able to do what I want with the UI without having to resort to shitty procedural code practices involving P/Invoke (whatever that means) and "owner draw" type of things for evertyhing.
WPF 提供了真正的开发简易性,而不是 winforms 所展示的虚假的开发简易性
WPF provides REAL ease of development as opposed to the fake ease of development exhibited by winforms
winforms 让你可以和设计师一起做所有事情(这只是因为设计师生成的代码实际上太糟糕了,如果没有设计师,没有人会用过 winforms)但是当它出现的时候要添加复杂的数据绑定或 UI 逻辑,您将永远被 winform 的无能所困.
winforms lets you do everything with a designer (and this is just because the code the designer generates is actually so shitty that nobody would have ever used winforms if they didn't have the designer) but then when it comes to adding complex DataBinding or UI logic you're stuck with winforms' incapabilities forever.
WPF 鼓励手动编写 XAML,这不仅是因为 XAML 是声明性的(与程序化的 winforms 方法相反),还因为可定制性和可重用性的级别如此之高,以至于以设计者为中心的方法没有意义.
WPF encourages manual XAML writing, not only because XAML is declarative (as opposed to the procedural winforms approach), but also because the levels of customizability and reusability are so high that a designer-centric approach does not make sense.
拖放是最简单的方法
不,不是.这实际上是一条艰难的道路.简单的方法是学习 XAML 并能够做到 用 Winforms 做你无法想象的事情.
No it's not. It's actually the hard way. The easy way is to learn XAML and be able to do Things you can't even imagine to do with winforms.
如果以设计师为中心的方法对您来说仍然有意义,您可能想尝试 Expression Blend
If a designer-centric approach still makes sense to you, you may want to try Expression Blend