开发者

WPF - XAML - C# - C++ - So Confused

I hope someone can assist, I am a beginner in computer programming and had purchased a book (Visual Basic - Step by Step), I was making good progress until I read an article on the internet about Windows Presentation Foundation (WPF) - apparently this the future.

I read up on Xaml and I find the syntax extremely difficult to understand, for instance I have been coding using the following format:

texbox1.text = "Hello World!"

However the guides I read on Xaml show that the coding in the .cs file are as follows:

<Grid>
    <TextBlock Text="Hello World!" />
</Grid>

I am confused on which 'language' I should be learn开发者_高级运维ing!

I hope someone can shed some light into this.

Many thanks


There are many aspects to programming, and it can certainly become overwhelming for a beginner quickly. For starters, let's clear up a few terms:

VB (Visual Basic), C#, and C++ (mentioned in your title) are all high-level programming languages. Assuming that when you say Visual Basic you are referring to VB.NET (which is likely, unless the book you're reading is a decade old...), VB and C# are both languages that can be used with Microsoft's .NET Framework, a set of libraries and tools for building (primarily Windows) applications.

(C++, meanwhile, is a slightly lower-level language not directly connected to .NET. It requires an understanding of certain concepts that the .NET languages hide from you, such as pointers and memory management.)

Now, the programming languages mentioned above are not tied to a specific presentation technology - there are many ways to create interactive programs that display output to users and accept input regardless of the the language you use. The .NET languages, however, are typically used alongside a couple of powerful tools that the .NET Framework provides for creating graphical applications:

  1. Among the simplest user interface methods, you can create a console program which takes typed input and produces text output on the system console. Nothing fancy here.
  2. Windows Forms - originally provided with the pre-.NET versions of Visual Basic, this is a venerable API to the native Windows user interface. It is driven primarily by Form objects that contain Controls and are driven by user Events. Here is a primer.
  3. WPF (Windows Presentation Foundation) is a newer technology than Windows Forms. It is used alongside an XML-like file format, which you've shown above, called XAML (eXtensible Application Markup Language) that lets you build user interfaces by quickly declaring a hierarchy of visual objects. The learning curve for building WPF applications is slightly higher (in my opinion) than that for Windows Forms, but it is a more versatile technology that better supports several good design patterns (that's hand-wavy, I know, but take my word for it for now).

So, to clear up a few points of confusion:

  • The programming language you use and the framework for building graphical user interfaces are two separate choices.
  • Both VB.NET and C# can be used to write the underlying logic for Windows Forms or WPF applications
  • WPF, the graphical subsystem, and XAML, the declarative markup language, are not the same thing, but they are used hand-in-hand with each other.
  • When creating WPF controls, you will have a file containing XAML (suffixed with .xaml) that is attached to a "code-behind" file containing C# (with a .cs extension) or VB (with a .vb extension), depending on which language you choose.

In general, a .NET programmer (which is an easy example for me to give, as I happen to be one) will use either VB or C# depending on what s/he is most comfortable with (or what's mandated by their team!) From a beginner's perspective especially, the two have different syntaxes but are functionally equivalent. I personally prefer C# for its similarity to the languages (Java and C) in which I learned to program.

Now, whatever the language, a programmer then selects the appropriate user interface technology for the project at hand. For graphical applications running on Windows, I believe that WPF is the tech to beat (especially because it's very similar to Silverlight, which can be used to target the web and Windows Phone).

I hope that at least begins the process of clearing up what is a very complex but navigable topic! I've already linked to it once above, but check out Microsoft's Beginner Developer Center as another resource to get you on your feet. Good luck!


The way you were coding and the xaml markup code does the same thing. The primary reason of XAML existence is to let the UI designers work on the UI using XAML and later programmers would tie up the business functionality using C# or XAML. XAML is primarily used in WPF but languages like C#, VB can be used to do a lot more things. Regarding what languages to learn, it all depends on your interest areas and your job.


djacobson's answer hits 90% of what I was about to write... so this is just a little supplement to that answer giving my personal advice.

If you're just starting out learning programming... it doesn't really matter too much where you start with which 'language' you choose. It looks like you've started out with learning Visual Basic. I write mostly in C#... but for the most part... they can do the same things, and are both good options to start learning about programming.

For your first couple of projects, simply create console applications that don't really have a user interface besides the command prompt (console).

As you move forward and want to start creating applications with a GUI (Graphical User Interface), then you can look into XAML (WPF if you're creating a desktop app, Silverlight if it's a web based app).

You'll still write your business logic code using Visual Basic or C#, the XAML is simply a way to define how your GUI will look and behave using the familiarity of XML rather than an older technology such as Windows Forms.

I'll be the first to say that I absolutely love WPF and XAML, but I truly feel that you're best off learning the basics of the language of your choice first, then work your way into the UI technologies later.


Since from last 2 years I am working on WPF and even I was like blank when it came to WPF. I would prefer C# over C++ and still you can find solutions for every language. But it depends on you what you are comfortable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜