I have an application that has some controls that use GDI+, mostly simple stuff with low graphics rendering requirements although I do have a couple of animated GDI+ windows that are borederline usable because of poor GDI+ performance.
Moving forward I would like to start using WPF (for performance and to learn WPF) but I also like to keep code compatible with Mono. As such I was wondering if I should or could develop using Silverlight (Moonlight in Mono). That way I get some WPF skills (I undertand silverlight is a subset of WPF?) and good performance.
Silverlight/Moonlight is a far better choice for any type of graphics and animations. GDI+ is old, and the Mono implementation exists mainly to support Winforms, which means it's not going to get any better. OTOH, while on the surface both use Cairo (as the previous poster mentions), that's like saying both render text - yes they do, but that's pretty much where the comparison stops. Moonlight is targeted for fast rendering, you get vectorial animations, you get hardware support whenever possible for graphics chips, because it really needs to be fast, it needs to support video with realtime render effects, 2D and 3D, etc. It might be that it's not yet up to par with the latest Silverlight version, but that doesn't mean it doesn't do what you need already. If you have the choice, go with new technology that's being actively worked on, not old stale tech.
Silverlight is indeed a subset of WPF allthough there are quite some details that work differently. Moonlight is currently compatible to Silverlight 2.0 but Microsoft is at 4.0 now with Silverlight. Moonlight will probably be always far behind Silverlight and even farer behind WPF. But if you can live with that, Moonlight might be a good choice. However if you will probably not see any perfomance improvements because Mono is using Cairo for rendering both GDI+ and Moonlight.
I also expect Mono's GDI+ implementation to be much more mature that the low level rendering APIs of Moonlight.
C# code that uses GDI+ instructions provided by System.Drawing currently are not compatible on Linux using Mono.
A null reference or invalid value was found [GDI+ status: InvalidParameter]
AFAIK no one was able to solve this error.
Related
I have been working for some time on a library which performs numeric calculations. It is written in pure native C++, and until now I have been using simple console applications to test its functionality.
The time has come to build a GUI on top of the library - to better display tables of results and also to render them in graphical form.
I was always planning to use WPF to implement the UI and have spent some time researching it, but I am now having second thoughts. My worries about WPF are:
Is it worth coupling my program to the .NET framework just for the sake of the user interface? .NET and WPF seem to add overhead in many forms, including:
Program complexity
Using .NET implies using a second language - and thus writing lots of messy interop code.
Runtime performance
In particular, WPF applications seem very slow to start up.
Deployment
Is .NET framework installation quick and easy? Does it require rebooting the machine?
Rendering quality
This has improved in WPF 4, but display of standard elements still seems poor in some areas.
Concern over whether performance and quality will improve in the future
Is it true that WPF is being de-emphasized within Microsoft (in favour of Silverlight)?
My worries are compounded by news of people moving away from WPF having faced similar issues - the most recent and highest-profile being Evernote.
Would you recommend I stick with my original plan and use WPF?
If so, what do you think about the above issues?
If not, what alternative libraries could I use to create a high-quality Windows GUI?
Edit:
Thanks to Reed Copsey for addressing my individual points. The reply suggests that most of the issues I have with WPF can be worked around.
It seems that using WPF will involve more work than would be ideal - including writing interop code and making tweaks to ensure good performance and high quality. Do people generally agree with the statement that, in spite of this, the best way to produce a top-quality UI is with WPF - rather than with any other framework?
I'll try to address these in order. Spoiler: In my opinion, for the most part, the answer is yes.
Is it worth coupling my program to the .NET framework just for the sake of the user interface?
This depends on the interface requirements. Do you users need a good, solid, modern UI? If so, you'll want to use the right tool to deliver that requirement.
.NET and WPF seem to add overhead in many forms, including:
Program complexity
Using .NET implies using a second language - and thus writing lots of messy interop code.
You can use GDI+ via C++/CLI, and handle everything in one language. That being said, part of the reason people use other languages for this is productivity - it's actually very, very fast compared to making a GUI in C++. The interop code via C++/CLI is not very messy at all, at least not if your routines are class-based.
Runtime performance
- In particular, WPF applications seem very slow to start up.
This can be an issue, to some extent. You can do a lot to mitigate it, however - but this will probably always be a bit slower to start than a lean, native codebase since it has to spin up the CLR + libraries.
Deployment
- Is .NET framework installation quick and easy? Does it require rebooting the machine?
Yes on both counts, typically. That being said, most people already have the framework installed (esp. if you target .NET 3.5, but 4.0 is coming along nicely), so it's a non-issue. I always see this as a one-time thing, though - I'd much rather trade a nice user experience for a bit of deployment time, especially when it's a relatively pain-free deployment (.NET's very easy to install, just large and a bit time consuming).
Rendering quality
- This has improved in WPF 4, but display of standard elements still seems poor in some areas.
I'd strongly disagree here. WPF is (esp. in v4), the premier platform for quality user interfaces. It's tough to beat the rendering quality options in WPF -
Concern over whether performance and quality will improve in the future
- Is it true that WPF is being de-emphasized within Microsoft (in favour of Silverlight)?
No. There was even a good talk at the PDC of the future of WPF. Silverlight gets a lot more press, but that's mainly because it's not nearly as mature of technology, so it's changing more quickly. WPF is still their top of the line UI experience, and still getting new features added. It's also the suggested platform for interop with native code - while it's possible in SL using COM, it's not pleasant like in WPF.
Performance, threading issues, and airspace issues seem to be the future improvements in mind, according to the PDC talk. For details, watch "The Future of WPF."
I’m working on creating a full-screen 3-D app (based on Johnny Lee's Wii head tracking app) with some augmented reality features, and it seems that WPF is too slow to render even the simple models I’m using at a reasonable frame rate. I think the problem is that I need to change both the view and projection of the camera on just about every frame, because of the nature of the app (it uses a web cam to track your face, and uses that data to move the camera around and change its perspective).
I've spent a lot of time trying to narrow down the problem, and it's definitely related to the graphics, and not the speed of the head-tracking API that I'm using. Also, I recreated the app in XNA, and it seems to work fine there (28 FPS versus 9 in WPF). Finally, when I remove the "walls" or make the window much smaller (say, 800 x 600), WPF's performance greatly improves, which makes me think that the bottleneck is the graphics calculations.
As a result, I need to either find a new graphics back-end to work with, or find a way to make WPF much faster for this app. I’m mostly looking at DirectX and XNA, and possibly OpenGL. Any recommendations on which of these APIs would be best to use for this app in .NET? Or alternatively, any idea what I'm doing wrong in WPF that's slowing things down?
I've not done enough with 3D in WPF to be able to say what could be causing the slowness, but I did notice that it's model datastructure isn't very efficient. While this might not be the cause it could be symptomatic of general slowness to the whole pipeline.
One thing that does spring to mind is that WPF is rendering the scene in software rather than using the hardware acceleration on the graphics card. The fact that you get better performance (though you don't say how much better) with a smaller window.
If you remove any textures from your model do you get better performance too?
I don't think it really matters whether you go for Direct3D or OpenGL - virtually all modern cards support them equally well. XNA is the obvious choice if you're sticking with .NET as it's integrated into Visual Studio - even the Express edition.
I would check out SlimDX, a much thinner DirectX wrapper than XNA or WPF
The problem with changing the projection on every frame is that API's like XNA/WPF werent designed with this in mind, so were optimized to have projection set once in the initialization phase, then not again.
I would suggest a hybrid choice here: use WPF for what its good at (Windows UI, composition, etc) and use XNA to render the 3D. There are samples out there that demonstrates combining XNA with WinForms. It should be possible to do the same "trick" to render XNA onto surfaces in WPF.
Update: there are supposedly issues with using XNA directly with WPF. This thread indicates that using XNA with WinForms and then hosting the WinForms control in WPF is a workaround to these issues. I've not tested this myself though (yet).
Is it possible to access a webcam in Silverlight
From what I've read it's not possible in Silverlight 1.0 but what about 2.0... 3.0 ... 4.0?
It is now possible in Silverlight 4.0. Developer preview is available at http://silverlight.net/getstarted/silverlight-4-beta/
I'm afraid webcam support isn't available in Silverlight 2.0. You might hope for it to be added in a future version, but there's no easy way of doing it now... Saying this, some people have invented various hacks that use other technologies in combination with Silverlight to capture video from the webcam. They typically involve interfacing with Flash, which of course is perfectly capable of utilising webcams. See this article for an example (with source code included). It's not a pretty solution (at least in my opinion), and may not be 100% stable across browsers/platforms, but I think it's the best you're going to get for now. Perhaps you should submit feedback directly to Microsoft if you really want to see support in Silverlight 3.0 (though it's certainly been mentioned elsewhere, so it may already be on the to-do list).
Silverlight 4 supports web cams. To capture images you can use www.glo6.com/camera1.aspx
It saves encoded images to web server. If there is a need to motion tracking, save images regularly, and then compare them on your server with another application.
I asked a member of the Silverlight team when they would be coming out with webcam support, and he said, in effect, "Let's just say that it's a really high priority for Silverlight 4.0." That said, it hasn't been officially announced yet, so I wouldn't count on it until MS does make the announcement.
I've used the Silverlight -> JavaScript -> Flash hack in production code, and while it does work, it doesn't work very well. Among other things, it's a pain to keep the Flash camera synchronized with your Silverlight UI. The camera shows up on top of SL child window controls, for instance, and of course, doesn't obey the clipping rules for when, say, it should be scrolling out of sight in a list box. And animations are a PITA as well. It's all possible, just slow and unpleasant, and several orders of magnitude more work than it would be if MS just supported web cams in Silverlight.
How is Silverlight going to change the internet in the next 10 years?
Is this going to be a scene changer or just another blip?
People often underestimate Microsoft. I don't know if it's going to change the Internet, but Silverlight will probably become pretty widely used, especially in web-based business applications that require rich interfaces. Flash is good, but being able to develop rich web interfaces with .NET and WPF is much nicer, particularly in that realm.
It will be another blip. It's not seriously cross-platform, unlike Flash or any of its other competition, and no one seems particularly interested in it. It might be neat and shiny but I haven't seen any real reason to move past playing around with it.
Put another way, it's a cool toy but not much else.
Until Silverlight has respectable implementations in other operating systems (read: OS X and Linux) and it can differentiate itself from Flash considerably, it's never going to grab a significant percentage of the rich content web app market, IMO.
I personally think Silverlight will be popular, its got a good "feel" about it IMO as a developer.
The cross-platform issue will be solved soon, as Mono continues to grow fast.
But I think it will be a very long time before anything knocks Flash/Flex off its perch on the top of RIA development platforms.
Silverlight allows the developer to offload some processing to a CLR on the client, using the native language such as C#, provide rich interfaces that are not restricted to HTML/CSS/DOM differences between browsers, and potentially reduce the need for scripting in javascript.
Although I might seem antagonistic here, I really, full heartedly don't like Silverlight, and I don't like Flash either.
They don't bring anything to the table anymore, now that browser are truly fast at rendering and processing. You can do most of the same things with pure Javascript and HTML/CSS. And what you can't do you will be able to do with HTML 5.0. What we need are not more proprietary frameworks, but better tools for what what we already have.
So my guess is 10 years from now, Silverlight and Flash won't be more than wikipedia articles.
I feel that while you can do most of what you need with Javascript and CSS, Silverlight programming feels much more fluid and fast to me. This is especially true when it comes to easily building a rich design with loads of animations. It is very easy for a team of designers and developers to collaborate on Silverlight and WPF projects, and that efficiency is important. Visual Studio being a fantastic IDE has kept many developers on the Microsoft ranch. The Expression suite feels like the next big advancement in allowing your IDE to do a lot of your work for you.
Deep Zoom is another big winner for Silverlight - check out the Silverlight implementation of the Hard Rock Memorabilia collection. Now look at the Flash implementation of SF Moma's art collection.
Don't knock Silverlight until you try it. I am no Microsoft fanboy, but it is very easy to use. People who have never developed using Microsoft technologies don't know the meaning of a good IDE.
I mostly develop with PHP, and I use Aptana for development. VS200x is lightyears ahead of any other IDE in just about everything.
The only real thing standing in the way of Silverlight becoming more widely used is better cross platform support; which would be pretty amazing thing I don't see happening at all. If Microsoft could loosen the reins up a bit, it would do wonders for it. Then again, Microsoft has gotten got at getting certain really good tools out there for free: The Express VS tools, the Dreamspark suite, etc.
One area that Silverlight will catch on is business applications. As architecture models shift into the service oriented realm there will be many companies looking to port their old client/server apps. Silverlight enables them to maintain the rich UI of the forms application while providing the messaging capabilities necessary to talk to the services. Also,t he deployment is wider than what they would get with strictly WPF and xbapps. Flash doesnt really compete in this area and a straight asp.net or other web technology front end, while getting nicer with Ajax and all that fun stuff, wouldnt support the richness you can get out of silverlight.
It seems that Silverlight/WPF are the long term future for user interface development with .NET. This is great because as I can see the advantage of reusing XAML skills on both the client and web development sides. But looking at WPF/XAML/Silverlight they seem very large technologies and so where is the best place to get start?
I would like to hear from anyone who has good knowledge of both and can recommend which is a better starting point and why.
Should you learn ASP.NET or Winforms first? ASP or MFC? HTML or VB? C# or VB?
Set aside the idea that there is a logical progression through what has become a highly complex interwoven set of technologies, and take a step back and ask yourself a series of questions:
What are your goals; how do you want to balance profit against enjoyment
Are you short term oriented or in for the long haul
Are you the type of person who likes to get good at something and do it a lot or do you get bored once you fully understand it?
The next and hardest step is to come to accept that any advice you are given is bound to be wrong; and the longer the time horizon the more likely it is to be incorrect. If the advice is for more than six to 12 months, the probability the advice is wildly incorrect approaches 1.
I can only tell you my story, quickly. In 2000 I was happy as a consultant working profitably in C++ on Windows applications, writing about ASP.NET and WinForms. then I saw C# and the world turned upside down. I never went back.
Two years ago I had the same kind of revelation, only an order of magnitude bigger, stronger and with more conviction about Silverlight. Yes, WPF is magnificent, and it may be that I'm all wet about this, but I believe in my gut that Silverlight changes everything. There was no doubt then and there is no doubt today that Silverlight is the most important development platform for Microsoft since .NET (certainly) and possibly since the switch to C++.
In a nutshell, here is why. I don't understand where its limitations are. With most platforms I do: you can do this, but you can't do that. WPF is a pretty good case in point, as was ASP.Net and WinForms and, well really everything until now.
With Silverlight, I don't see the boundaries yet. Silverlight has already leaped off the desktop onto phones, and I don't see any reason for it to stop there. Yes, it is true, it is bound by the browser, but I see that less as a jail cell than as a tank in which Silverlight will be riding over lots of terrain (it must be very late, I should go to bed).
In any case, for now, learning Silverlight is a gas, there is a lot of material on the Silverlight.net site, and what is the very best thing about learning Silverlight is that if you don't see what you need you can holler at me and I'll make sure you get it pretty quickly.
Enjoy, good luck and the dirty little secret is you'll be fine whichever you choose. It's all just software.
-jesse
Jesse Liberty
"Silverlight Geek"
I'd say go with Silverlight first!
I have programmed with WPF and Silverlight before.
But as Silverlight is a subset of WPF if you go in too deep and try to switch to writing Silverlight applications, you'll be scratching your heads looking for that "tag" you learned to love in WPF but is not available in Silverlight.
When you master the basic things in Silverlight first, the extra mechanism/trigger/whatever features in WPF will simply add to most of what you've already known.
Silverlight in WPF differs at the features level, not just some missing controls or animations. Take the WPF triggers mechanism for example, is not available fully in Silverlight.
So learning the smaller subset first, you can extend that knowledge to the full set later, but if you started at the full set and gets addicted to some of the niceties available, you'll have trouble down the line when someone asks you to port your designed-utilizing-WPF apps to Silverlight.
I'll go against the grain and say learn WPF first.
Here's my reasoning:
Much more resources are available for WPF than Silverlight, such as books, blogs, and msdn documentation
WPF Books
You're not dealing with a Beta, moving target
You don't have to deal with working with only asynchronous calls
Not limited by lack of features such as Merged Dictionaries, Triggers, TileBrushes, etc.
You don't have to worry about re-learning to do things correctly because of lacks of features in SL
Silverlight is a stripped down version of WPF so it should have fewer things to learn inside. On the other hand, the two platforms have different targets (web & rich client) so I guess it depends on what app you're going to build.
If you just want to learn for yourself (no app in the close future) I'd pick Silverlight because it would be less to assimilate. Still, Silverlight is pretty much a moving target, much more than WPF, so you'll have to keep up with some changes from time to time (the joys of being an early adopter :)).
WPF has lots more stuff that you will probably want to use at some point but I would wait for the needs to arise first.
Every industry expert I've heard on podcasts, blogs and interviews recommend learning Silverlight first and then gradually moving to WPF which is a huge UI framework.
Silverlight is light and allows you to work on smaller subset of controls and features such that you get your head around this new UI building paradigm based on,
Templating
DataBinding
Styles
Update: 07/2011
I hate to mention this, but in recent times Microsoft has put more focus on HTML5, Javascript and CSS by bringing forward powers of IE 9 and IE 10, as well as the upcoming Windows 8.
More and more developers and CTOs are skeptical about Silverlight as a LOB application platform as the time passes by, we are suspecting Silverlight will be limited to Windows Phone and niche, domain areas like healthcare of graphics related applications rather than a regular LOB app.
As it seems right now, as of summer 2011, the future might look fragmented with more opportunities for pure web technologies (HTML5, JS and CSS) as opposed to a plugin and OS-specific UI technology.
I would start by learning XAML, by reading a few tutorials and playing around with XAMLPad. This will give you a feel for the basics before actually building an app.
I would start with WPF and doing very simple control familiarizaton samples. You goal should be to learn XAML and Binding. So if you just create some basic WPF window apps will bootstrap your learning speed. Then eventually you can move to silverlight. Yeah as other mentioned here Silverlight is a subset of WPF.
Well, it depends on what you are going to be working on. If you are working on client/server, then I would go with WPF. If you are working in an environment where you can guarantee that .Net is installed on all of the machines, then I would go with WPF as well, because you can use what is called an XBAP, which is a WPF application that is run through the browser.
It's really up to you. However, I would state that silverlight is not RTM yet, and WPF is. WPF has a lot of books out on the subject, where silverlight does not. It may be easier to get the whole Zen of WPF by reading a few of those books, and then dive into which ever one you would like to play with.
Just keep in mind that silverlight has a subset of the controls of WPF, a paired down .Net framework, and does not do synchronous calls. As long as you know that up front, you can start learned the core of the whole foundation and tailor your practical experience later on to whichever technology is best for you.
Some tips at Getting started with Silverlight Development