简体   繁体   English

XAML 或 C# 代码隐藏

[英]XAML or C# code-behind

I don't like to use XAML. I prefer to code everything in C#, but I think that I am doing things wrong.我不喜欢使用 XAML。我更喜欢在 C# 中编写所有代码,但我认为我做错了。

In which cases it is better to use XAML and when do you use C#?在哪些情况下最好使用 XAML,什么时候使用 C#? What is your experience?你的经验是什么?

Creating an entire window in C# can be a mess of code.在 C# 中创建整个 window 可能是一团乱码。 The best thing about WPF is that XAML allows you to separate your design from your logic, making for much easier-to-read code. WPF 最好的一点是 XAML 允许您将设计与逻辑分开,从而使代码更易于阅读。

I'll use C# when I need to create dynamic controls, but I tend to keep my general design, static storyboards, styles, datatemplates, etc. in XAML.当我需要创建动态控件时,我将使用 C#,但我倾向于将我的一般设计、static 故事板、styles、数据模板等保留在 XAML 中。

Check out this video on MVVM in WPF. If you want wrap your head around how to organize a WPF application vis-a-vis what goes in XAML, code behind and other abstractions, this is a great place to start.观看 WPF 中有关 MVVM 的视频。如果您想了解如何组织 WPF 应用程序,以及 XAML 中的内容、代码隐藏和其他抽象,这是一个很好的起点。

You can certainly go too far with XAML. Those who want their entire user interface (including logic, event handling relationships, etc) defined in XAML are probably missing the point.你当然可以 go 与 XAML 太过分了。那些想要在 XAML 中定义其整个用户界面(包括逻辑、事件处理关系等)的人可能没有抓住要点。

The aim of XAML is to provide a common format for determining how things should look . XAML 的目的是提供一种通用格式来确定事物的外观 It should just be a description of how to lay things out, how to color and style them visually.它应该只是描述如何布置事物,如何在视觉上为它们着色和设计样式。

There is really very little point in trying to use it as a replacement for other aspects of C#, because C# has a permanent head-start in terms of programming features - reuse (defining types and functions), referring to variables, procedural programming, and even declarative or functional styles.试图用它来替代 C# 的其他方面确实意义不大,因为 C# 在编程特性方面具有永久的领先优势——重用(定义类型和函数)、引用变量、过程式编程以及甚至声明性或功能性 styles。

Personally I really like throwing together a UI with a Linq expression!就我个人而言,我真的很喜欢将带有 Linq 表达式的 UI 拼凑在一起!

The ultimate absurdity was reached by a sample I saw where they used workflow actions as the children of a button to supply the Click handler, so the whole program was in XAML. It sounds "cool", but the problem was that it was significantly more ugly and unreadable than the equivalent C# or VB.NET program, and so everything that is ready to use in C# has to be replaced by a more verbose, flaky equivalent.最荒谬的是我看到的一个示例,他们使用工作流操作作为按钮的子级来提供Click处理程序,所以整个程序在 XAML 中。听起来“很酷”,但问题是它明显更多比等效的 C# 或 VB.NET 程序丑陋且不可读,因此 C# 中准备使用的所有内容都必须替换为更冗长、易碎的等效程序。 Nothing has actually been gained by this translation to an uglier syntax - it's the same program only more hideous.这种翻译成更丑陋的语法实际上并没有带来任何好处——它只是更丑陋的同一个程序。 XML is a poor basis for the syntax of a general programming language. XML 是通用编程语言语法的基础很差。 Start with the fact that the greater-than symbol has to be written as >从大于号必须写成>的事实开始。 !

In a parallel universe, Microsoft released C# 3.0 before they finished XAML. The XAML team adopted C# 3.0 object/list initializer syntax instead of XML as their syntax.在平行宇宙中,Microsoft 在完成 XAML 之前发布了 C# 3.0。XAML 团队采用 C# 3.0 对象/列表初始化语法而不是 XML 作为他们的语法。 And this whole debate never happened.整个辩论从未发生过。

My experience is that some things are far quicker to do in C#, while most are quicker to do in XAML. When it takes 5 lines of C# code to do what a single line of XAML code can do, it's pretty easy for me to choose which is better.我的经验是,有些事情在 C# 中做起来要快得多,而大多数事情在 XAML 中做起来更快。当需要 5 行 C# 代码来完成一行 XAML 代码可以做的事情时,我很容易选择哪个更好。

Basically, XAML is meant for expressing visual-design, C# is meant for expressing logic.基本上,XAML 用于表达视觉设计,C# 用于表达逻辑。

Any visual design should be done in XAML, any logic should be implemented in C#.任何视觉设计都应该在XAML中完成,任何逻辑都应该在C#中实现。

- This enables giving the visual design to a designer to play on without worrying about changes to the logic and even replacing the entire visual design at run time using loose-XAML. - 这使得设计人员可以继续使用视觉设计,而不必担心逻辑的变化,甚至可以在运行时使用松散的 XAML 替换整个视觉设计。

- This also means you could replace either the logic or the visual-design without "breaking" either. - 这也意味着您可以在不“破坏”的情况下替换逻辑或视觉设计。

- The connection between the two should be done with data bindings and with command bindings. - 两者之间的连接应该通过数据绑定和命令绑定来完成。

The practice I use is:我使用的做法是:

1. Define the model (the business data object model) in separate C# code. 1.在单独的C#代码中定义model(业务数据object模型)。

2. Define the constant parts of the view (the constant parts of the graphical user interface, eg the windows, menus, ...) in XAML (preferably use Blend and not VS for this). 2. 在 XAML 中定义视图的常量部分(图形用户界面的常量部分,例如 windows,菜单,...)(为此最好使用 Blend 而不是 VS)。
* Do not define styling (colors, fonts, ...) here. * 不要在这里定义样式(颜色,fonts,...)。
* Do not write event handlers for buttons (in most cases) in code-behind-the-XAML, use command-bindings instead. * 不要在 XAML 代码隐藏中为按钮编写事件处理程序(在大多数情况下),而是使用命令绑定。

3. Define how the model is presented within the view (the GUI for viewing/editing the data objects) using XAML "ResourceDictionary"s located in separate files. 3. 使用位于单独文件中的 XAML“ResourceDictionary”定义 model 在视图(用于查看/编辑数据对象的 GUI)中的呈现方式。

- Write using blend then add bindings to XAML using VS (Jetbrains' Resharper add-on for VS will help with binding expressions). - 使用 blend 编写,然后使用 VS 将绑定添加到 XAML(Jetbrains 的 VS Resharper 插件将有助于绑定表达式)。

- If the object types are not known during design-time you can use "loose-XAML" and place the XAML in a folder which can have files added to / edited within without recompiling. - 如果在设计时不知道 object 类型,您可以使用“松散 XAML”并将 XAML 放在一个文件夹中,该文件夹可以在不重新编译的情况下添加/编辑文件。

4. Create a connection between the model and the view (a controller/view-model) in C# which: 4. 在 model 和 C# 中的视图(控制器/视图模型)之间创建连接,其中:
* Creates views as necessary (for dynamics objects) * 根据需要创建视图(对于动态对象)
* Data-binds the view to the model (sets view's DataSource as the relevant object within the model) * 将视图数据绑定到 model(将视图的数据源设置为模型中的相关 object)
* Implements the commands * 执行命令
* Command-binds the view to the command implementations within itself *命令将视图绑定到其自身内的命令实现

5. In Application.xaml delete the StartupUri="MainWindow.xaml" and add Startup="ApplicaitonStartUp" instead. 5. 在 Application.xaml 中删除 StartupUri="MainWindow.xaml" 并改为添加 Startup="ApplicaitonStartUp"。
Within the ApplicationStartUp() event handler:在 ApplicationStartUp() 事件处理程序中:
* Load any loose-XAMLs you have * 加载您拥有的任何松散 XAML
* Create the controller * 创建 controller
* Create the main window * 创建主体 window
* Create the model * 创建 model
* Connect controller to model and main window * 连接 controller 到 model 和主 window
* Show main window * 显示主 window
* (Save model, controller and main window into private fields here to make sure they are all kept alive) *(将 model、controller 和 main window 保存到此处的私有字段中,以确保它们都存活)

6. Add styling (colors, fonts) to a separate XAML file under a ResourceDictionary (using blend for this or purchase a ready made XAML theme/skin file). 6. 将样式(颜色、字体)添加到 ResourceDictionary 下的单独 XAML 文件(为此使用混合或购买现成的 XAML 主题/皮肤文件)。

The urge to want to write your UIs in C# instead of XAML is really just a manifestation of how comfortable you are in XAML.想要在 C# 而不是 XAML 中编写 UI 的冲动实际上只是表明你在 XAML 中有多舒服。

For me, is is a personal goal to write as little code-behind as possible.对我来说,编写尽可能少的代码隐藏是我的个人目标。 Quite simply put, code behind is hard to unit-test, but can (and usually does) include logic that doesn't get tested.简而言之,代码隐藏很难进行单元测试,但可以(而且通常确实)包含未经过测试的逻辑。 XAML is declarative (like HTML) and doesn't include any logic, so there is nothing to unit-test. XAML 是声明性的(类似于 HTML)并且不包含任何逻辑,因此无需进行单元测试。 I keep my view code in XAML and I keep my view logic in my ViewModel (MVVM) which is VERY easy to test.我将视图代码保存在 XAML 中,并将视图逻辑保存在非常容易测试的 ViewModel (MVVM) 中。

Once you become more comfortable with XAML, the more you will realize its benefits over view construction in procedural code... Using a pattern like MVVM, you take it a step further, and realize that code-behind is only useful in rare cases.一旦您对 XAML 更加熟悉,您就会越多地意识到它在过程代码中相对于视图构造的优势......使用像 MVVM 这样的模式,您更进一步,并意识到代码隐藏仅在极少数情况下有用。

The most important thing to bear in mind is that XAML is for presentation.要记住的最重要的事情是 XAML 用于演示。 All your presentation should be in the XAML. If you have logic, you keep that out of your XAML - in your C#.您的所有演示文稿都应在 XAML 中。如果您有逻辑,请将其保留在 XAML 之外 - 在您的 C# 中。

Imagine swapping out your XAML file with one that LOOKS completely different - but still uses the same data - that's where the division should be.想象一下,将您的 XAML 文件换成一个看起来完全不同的文件——但仍然使用相同的数据——这就是应该划分的地方。

One of the nice things about XAML is the separation of presentation an logic. XAML 的优点之一是表示与逻辑的分离。 This separation is not just theoretical but also practical.这种分离不仅是理论上的,而且是实践上的。 I my case, most of the my UIs are now being handled by a designer.我的情况是,我的大部分 UI 现在都由设计师处理。 This designer uses blend and does not know C#, has no interest of learnning c#, and frankly should not need to.这位设计师使用blend,不知道C#,没有兴趣学习c#,坦白说应该不需要。 This designer is a true designer, an artist, that knows how to use those tools to make things look really really nice.这位设计师是一位真正的设计师,一位艺术家,他知道如何使用这些工具让东西看起来非常漂亮。 Basically my phylosipy is this, the more I use XAML, the less work I have to do on the UI because he can do it.基本上我的phylosipy是这样的,我使用XAML越多,我在UI上做的工作就越少,因为他可以做到。 This has worked well for us.这对我们很有效。 I usually design my control to be lookless, give them a basic no frill look, use the DataContext to bind my object(btw DataTriggers are a great way to cut down on code).我通常将我的控件设计为无外观,为它们提供基本的简洁外观,使用 DataContext 绑定我的对象(顺便说一句,DataTriggers 是减少代码的好方法)。 As a result, I will often checkin my code, come back the next day, synch it, and the UI will look completely different, but everything still work!!!因此,我会经常检查我的代码,第二天回来,同步它,UI 看起来完全不同,但一切仍然有效!

Of course, it took at least 1/2 year to get there, but now this model seem to work and our UI look Kick A##, our application earns high praise, and I do little work on the UI itself and get to work on cooler things.当然,至少花了 1/2 年才到达那里,但现在这个 model 似乎可以工作,我们的 UI 看起来很棒##,我们的应用程序赢得了高度赞扬,我在 UI 本身上做了很少的工作并开始工作更酷的东西。 To make a long story short, I think the code behind might be a bit more developer centric and forgets a whole other group that can benefit, trive, and make a living using WPF, namely the designers.长话短说,我认为背后的代码可能更以开发人员为中心,而忘记了整个其他可以使用 WPF 受益、努力和谋生的群体,即设计师。

Of course, there are still times when it takes a devloper to make XAML/WPF sing and dance, and sometime we need to educate the designers about the right way to do things, but I think its worth the investement pays off many times over in large scale projects (maybe not so in short one0当然,有时仍然需要开发人员让 XAML/WPF 唱歌跳舞,有时我们需要教育设计人员正确的做事方式,但我认为在大型项目(也许不是简而言之 one0

XAML, MXML all these stuff works as long as you are developing a simple UI with some average complexity. XAML,只要您正在开发具有一定平均复杂度的简单 UI,所有这些东西都可以使用 MXML。 Once your UI gets complex and richer, the automatic data bindings will cause more trouble than their benefits.一旦您的 UI 变得复杂和丰富,自动数据绑定将带来更多麻烦而不是它们的好处。 The purpose of XAML is not make programming easy, it is to seperate UI from logic so that tooling of UI can be easy.. XAML 的目的不是让编程变得容易,而是将 UI 从逻辑中分离出来,这样 UI 的工具就可以很容易..

No Data bindings, No Event handlers.. assume that you will never see your XAML again and write code..没有数据绑定,没有事件处理程序..假设你永远不会再看到你的 XAML 并编写代码......

XAML is presentation. XAML 是介绍。 Data binding is not presentation.数据绑定不是表示。 its presentation logic.它的呈现逻辑。 put all presentation logic in code behind (data binding and handlers).将所有表示逻辑放在代码后面(数据绑定和处理程序)。 Developers own code behind, Designers own XAML. if you are a developer and if you are touching XAML, then move that part in to code behind.开发人员拥有代码隐藏,设计师拥有 XAML。如果您是开发人员并且正在接触 XAML,则将该部分移至代码隐藏。

we can write WPF apps without XAML too..我们也可以在没有 XAML 的情况下编写 WPF 应用程序..

Thanks Vinoth Kumar R (Had gone thru enough using Flex MXML data binding)感谢 Vinoth Kumar R(使用 Flex MXML 数据绑定已经足够了)

It's not just about you, it's also about your team, some of whom may be designers.这不仅与您有关,也与您的团队有关,其中一些人可能是设计师。

XAML and C# is a really good way to separate the logic from design as already described.如前所述,XAML 和 C# 是将逻辑与设计分离的非常好的方法。

For a typical programmer the way of programming is really changed by using WPF, assuming that the programmer comes from a C++, VB, WinForms, ATL and MFC background, a background from were the UI was not as natural separated from the logic as with XAML and C#.对于一个典型的程序员来说,使用WPF真的改变了编程方式,假设程序员来自C++,VB,WinForms,ATL和MFC背景,UI与逻辑的背景不像XAML那样自然分离和 C#。

To get used to this way of programming it takes some time, but getting more and more experiance it gets really effective.习惯这种编程方式需要一些时间,但随着经验的积累,它会变得非常有效。

Before starting it is really good to learn the MVVM pattern and to run tutorials to understand the strength of the pattern, and also to get to understand its benefits.在开始之前,学习 MVVM 模式并运行教程以了解该模式的优势以及它的好处是非常好的。

WPF and C# applications based on MVVM pattern benefits: WPF和C#应用基于MVVM模式的好处:

1. User Experiance and Usability Separating the logic from UI, makes it more natural to have a dedicated designer working on the UI design and animations. 1. 用户体验和可用性将逻辑与 UI 分离,让专门的设计师负责 UI 设计和动画变得更加自然。 In that way the programmer can focus on the logic behind and the technical solution while the UI is designed by someone that knows design.通过这种方式,程序员可以专注于背后的逻辑和技术解决方案,而 UI 则由懂设计的人设计。 That has been a problem for many software companies, atleast in the industry that the programmers actualy are the once that are designing the UI as well and that has resulted in a lot of support, maintance and in effecive applications.对于许多软件公司来说,这一直是一个问题,至少在行业中,程序员实际上也是设计 UI 的人,这导致了大量的支持、维护和有效的应用程序。

There is a higher probability that it ends up with more user friendly applications by have a person with Usability background focusing on the usage instead of the technical solution.通过让具有可用性背景的人专注于使用而不是技术解决方案,它更有可能最终得到更用户友好的应用程序。 There is really interesting book abbout such examples, User Interface Design for Programmers, by Joel Spolsky.关于此类示例,Joel Spolsky 着有一本非常有趣的书《程序员的用户界面设计》。

By using the MVVM pattern for XAML application there is a good chance we will see more user firendly applications.通过对 XAML 应用程序使用 MVVM 模式,我们很有可能会看到更多用户友好的应用程序。

2. Maintanence Maintenance, which is cost a lot within software development. 2. Maintanence维护,在软件开发中成本很高。 It can feel that the MVVM pattern is a big overhead in the begining but while functions are added and the more complex and advanced the application is getting the more benefitial it is.可以感觉到 MVVM 模式在开始时是一个很大的开销,但是随着功能的添加,应用程序越复杂和高级,它就越受益。 You will see that it is really easy to maintaine such an application.您会发现维护这样一个应用程序真的很容易。 For an overview you can look into this video:有关概述,您可以查看此视频:

3. Mix of competences Dedicated designer and a dedicated programmer working in a team to achieve a better result is a very good way of mixing competences. 3. 能力的混合 专门的设计师和专门的程序员在团队中工作以获得更好的结果是混合能力的一种很好的方式。 Instead of only hiring programmers organizations need to combine the competences to provide the best results.组织需要结合能力来提供最佳结果,而不是只雇用程序员。

4. Opportunity for design interested programmers Finally it is possible to implement fancy applications in the Windows environment. 4. 对设计感兴趣的程序员的机会最后,可以在 Windows 环境中实现花哨的应用程序。 If you are a programmer that are interested in design the Microsoft Expression Blend really opens up possiblities to learn and achive fancy, useful applications with a nice design.如果您是一名对设计感兴趣的程序员,Microsoft Expression Blend 确实为您提供了学习和实现具有漂亮设计的精美实用应用程序的可能性。

There can though be risk using with XAML and C#, MVVM or not, the great possibilities and flexibility it provides can also be a drawback.尽管使用 XAML 和 C# 可能存在风险,无论是否使用 MVVM,它提供的巨大可能性和灵活性也可能是一个缺点。 Letting the programmer loose with this new easy UI environment, the applications may end up with a wide spectra of animations, colors, everything this new environment provides.让程序员在这个新的简单 UI 环境中放松,应用程序最终可能会出现各种各样的动画,colors,这个新环境提供的一切。 Remebering how you added UI controls in the C++ and ATL envrionment.记住您如何在 C++ 和 ATL 环境中添加 UI 控件。

Still the benefits are more and I hope you get some inspiration to use XAML instead of C# for the UI, when getting used to it I am convinced you will like it.仍然有更多的好处,我希望你能得到一些启发,使用 XAML 而不是 C# 作为 UI,当你习惯它时,我相信你会喜欢它。

A link to a good tuturial: Tutorial MVVM XAML C#指向一个好的教程的链接:教程 MVVM XAML C#

I originally came from the Web side of development and am learning WPF/Silverlight at the moment.我最初来自 Web 开发方面,目前正在学习 WPF/Silverlight。 For me, the XAML model makes much more sense to me than WinForms ever did.对我来说,XAML model 比 WinForms 更有意义。 I treat the XAML as if it were HTML and the.cs files just like a code-behind.我将 XAML 视为 HTML,将 .cs 文件视为代码隐藏。

I love clean code, the less code I have, the cleaner it is.我喜欢干净的代码,我拥有的代码越少,它就越干净。 Code can be written in millions of ways, XAML is more restrictive.代码可以有数百万种写法,XAML限制性更强。 XAML is good at cutting down code, when appropriate of course. XAML 擅长削减代码,当然在适当的时候。 If I can put something in XAML, I'll do it.如果我能在 XAML 里放点什么,我就去做。 Tools can read XAML and do stuff with it.工具可以读取 XAML 并对其进行处理。 Much less with code.更少的代码。 Tools and frameworks handling XAML will evolve and get better, doing more and better work with existing XAML. Can't say that about code.处理 XAML 的工具和框架将发展并变得更好,与现有的 XAML 一起做更多更好的工作。关于代码不能这么说。 The more XAML evolves, the more we'll be able to declaratively define our applications. XAML 发展得越多,我们就越能够以声明方式定义我们的应用程序。

For me, using XAML is like using LINQ. If I can write a one line statement that is easy to read and let a framework decide the best way to implement what I want, I feel good.对我来说,使用 XAML 就像使用 LINQ 一样。如果我能写一个易于阅读的一行语句,让一个框架决定实现我想要的东西的最佳方式,我感觉很好。 I definitely try, as much as I can, to use declarations of what I want instead of hardcoding how I want it to be done.我绝对会尽我所能地尝试使用我想要的声明,而不是硬编码我希望它如何完成。 F# is another good example of this paradigm. F# 是这种范式的另一个很好的例子。

It seems no answers mentioned an important point yet: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465340.aspx似乎没有答案提到重要的一点: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465340.aspx

XAML is just procedural code (only easier) XAML 只是程序代码(只会更简单)

<Grid x:Name="ContentPanel" Margin="12,0,12,0">
    <Button Height="72" Width="160" Content="Click Me" />
</Grid>

"The following shows how this XAML could be partially replaced by code written in C# or Visual Basic." “下面显示了如何用 C# 或 Visual Basic 编写的代码部分替换此 XAML。”

// Initialize the button
Button myButton = new Button();
// Set its properties
myButton.Width = 160;
myButton.Height = 72;
myButton.Content = "Click Me";
// Attach it to the visual tree, specifically as a child of
// a Grid object (named 'ContentPanel') that already exists. In other words, position
// the button in the UI.
ContentPanel.Children.Add(myButton);

If you worked with windows forms for example, you probably remember the windows forms designer generates a.designer.cs file containing code similar to the example from the link above.例如,如果您使用 windows forms,您可能还记得 windows forms 设计器生成一个.designer.cs 文件,其中包含与上面链接中的示例类似的代码。 That kind of declarative code is much better represented in XAML than C#.这种声明性代码在 XAML 中比在 C# 中表现得更好。

For any non-toy application you should ALWAYS prefer XAML to define UI and connect it to logic in a MVVM manner.对于任何非玩具应用程序,您应该始终更喜欢 XAML 来定义 UI 并将其以 MVVM 方式连接到逻辑。

All logic should be in code regardless what you programming language that you use in computer programming.无论您在计算机编程中使用什么编程语言,所有逻辑都应该在代码中。 XAML should never replace that even in ControlTemplate although it is nice but it is far much easier to unit test and debug code. XAML 即使在 ControlTemplate 中也不应替换它,尽管它很好,但单元测试和调试代码要容易得多。

Some things are easier to maintain or debug in code.有些东西在代码中更容易维护或调试。

Not to Mention that you will be able to do more in Xaml2009 that has to be done in code behind now.更不用说您将能够在 Xaml2009 中完成更多现在必须在代码中完成的工作。

Unfortantly BAML won't fully support xaml 2009 in vs 2010 time frame so you can't compile xaml in 2010 time frame.不幸的是,BAML 不会完全支持 xaml 2009 vs 2010 时间框架,因此您无法在 2010 时间框架内编译 xaml。 And will have to wait for a later version of blend to do the full dev design loop.并且将不得不等待更高版本的混合来完成完整的开发设计循环。 (later than 3) (晚于 3)

Douglas道格拉斯

XAML can be seen as being similar to a combination of XHTML and CSS or XML and XSL which are used for structure and design. XAML可以看成类似于XHTML和CSS或者XML和XSL的组合,用于结构和设计。 Any form of logic should be in C#. This way structure and design are seperated from logic.任何形式的逻辑都应该在 C# 中。这样结构和设计就与逻辑分离了。 Your code should be cleaner too by using this approach.通过使用这种方法,您的代码也应该更清晰。 Another positive thing is that tasks can be easier to separate between designers and programmers.另一个积极的事情是设计人员和程序员之间的任务可以更容易地分开。

One more thing... this is the definition of XAML from MSDN:还有一件事......这是来自 MSDN 的 XAML 的定义:

Extensible Application Markup Language (XAML) is a markup language for declarative application programming.可扩展应用程序标记语言 (XAML) 是一种用于声明性应用程序编程的标记语言。 Windows Presentation Foundation (WPF) implements a Extensible Application Markup Language (XAML) loader and provides Extensible Application Markup Language (XAML) language support for Windows Presentation Foundation (WPF) types such that you can create the majority of your application UI in Extensible Application Markup Language (XAML) markup. Windows Presentation Foundation (WPF) 实现可扩展应用程序标记语言 (XAML) 加载器并为 Windows Presentation Foundation (WPF) 类型提供可扩展应用程序标记语言 (XAML) 语言支持,以便您可以在可扩展应用程序标记中创建大部分应用程序 UI语言 (XAML) 标记。 In addition, the SDK includes a Extensible Application Markup Language (XAML) editing tool called XAMLPad.此外,SDK 还包括一个名为 XAMLPad 的可扩展应用程序标记语言 (XAML) 编辑工具。 You can use this tool to experiment with Extensible Application Markup Language (XAML) in real time.您可以使用此工具实时试验可扩展应用程序标记语言 (XAML)。

Link to quote.链接到报价。

Programming WPF in C# with a fluent style helps keep the code size and complexity down.使用流畅的风格在 C# 中编程 WPF 有助于降低代码大小和复杂性。 See this answer for an example of using a fluent style with WPF.有关使用 WPF 的流畅样式的示例,请参阅此答案

It's mostly preference I think.我认为这主要是偏好。 I use WPF, since it's easier to structure different screens and separate the C# code logic from the UI.我使用 WPF,因为它更容易构建不同的屏幕并将 C# 代码逻辑与 UI 分开。 Typically all my logic is structured in another C# library than my UI which is the startup project in WPF or Windows Forms通常,我所有的逻辑都在另一个 C# 库中构建,而不是我的 UI,它是 WPF 或 Windows Forms 中的启动项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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