Embedding Silverlight control in WPF app - is it possible? - wpf

Background:
One of the most attactive feature of Silverlight is PlanProjection because of its ease of use and the stunning effect. Unfortunatelly, it is not available in WPF. I know that similar effects can be achieved using Viewport3D but certainly not with that simplicity.
The App:
I would like to build a Win app designed for dualscreen computer, a bit similar to PowerPoint: 1 fullscreen viewer window for the audience, and 1 regular window to control the app.
The problem:
Building the app in SL is not very appealing: Going to fullscreen always requires user confirmation due to (understandable) security reasons. Detecting primary/secondary screens, their positions is only possible with System.Windows.Forms.Screen class (pls, correct me if I am wrong), which is not available in SL.
The odd solution:
Would it be possible to write my controls in SL utilizing the fancy and simple PlanProjection features and reuse them within a WPF application?
If yes, what impact will I have on the installer? I assume that the installer would need to deploy both .NET framework and SL runtime.
Do you have alternative ideas to facilitate cherry-picking features from the two different worlds?

WPF has rich 3-D capabilities that are far greater than what Silverlight 4 can do so if PlanProjection is the main feature from SL that you require but want to create a desktop application then using WPF all the way would be the way to go. WPF can do everything that PlanProjection can do. Charles Petzold wrote an excellent book on WPF 3-D.

Just use Planerator : http://blogs.msdn.com/b/greg_schechter/archive/2007/10/26/enter-the-planerator-dead-simple-3d-in-wpf-with-a-stupid-name.aspx

Related

Why do WPF apps look like web pages?

I apologize for my newbie question by why do WPF apps look like web pages?
I am new to gui and still shopping for a book to learn gui programming. The push seems to be in the direction of WPF but all the screenshots of WPF applications that I've seen look like cheap web pages. Frankly I'd be ashamed to sell an app that looked like a web page.
I realize that WPF is built on XML technology but can you not build normal looking WPF apps in Visual Studio (via button("widget")) drag-n-drop? In other words an app that does not look like a web page?
How can WPF be a replacement for WinForms or the like when it doesn't provide the same standard application look?
The default look of WPF applications is admittedly rather simple, but WPF allows unprecedented control over how your application looks.
Here are some examples, all of them WPF applications.
If you are to deveop an application under .net and are able to target .net 3.5 or above, you will want to use wpf. If you don't know much about ui technology and want to work with .net, understanding windows forms is useful but not necessary. You should learn wpf regardless.
2 perks that I have found while using the framework:
- it is very easy to inject branding and custom interactivity into your app. It is then very easy to change these when your sales guy decides the want it blue, not red.
- the way components are organized on screen is relational like a webpage, not coordinate based like windows forms. This is ideal for scenarios when translated strings will change length (English to German for example). Under usual circumstances the ui will resize itself automatically at runtime to make it all fit.
If you just throw in controls and don't change the style of anything, your first wpf applications will look almost identical to native win32 applications. It is very easy to change this, but you will achieve great results regardless of the "look" you choose. Microsoft also provide the tools to create new ui components that look like native buttons. There are a host of other features that will make you grin while learning!
This is not a technical note, but at the moment wpf is a highly sellable skill and looks great on a cv! Companies want great branding in their apps. Wpf helps that happen.
WPF does provide the same appication look wich is the default look. When you drag and drop your controls onto the design surface (just like in windows forms, MFC ...) the controls look as you would expect them to look under the current theme. Chances are that you have seen quite some WPF applications without noticing. Just because they look like any other app.
The reason you might see more WPF based applications that have some sort of custom look and feel to them is simple because it is so much easier to do what ever you like to your GUI than in any other GUI framework on any platform. This is both blessing and curse. While you being absolutely flexible it is easy to do absolutely horrible stuff.
user440267, I believe that the most application in WPF are built using normal Windows. But there is an option which we don't create a window, instead we create a page, which behave like you think.

Can I replace WPF by Silverlight

Could Silverlight and WPF be interchangeable?
I mean, using Silverlight for Windows applications and WPF for web applications.
Silverlight and WPF are similar, but not interchangeable.
Silverlight and WPF are two different technologies intended to solve different problems. Silverlight has out-of-browser functionality, but must be delivered over the web in a browser first. WPF has XBAP, but it's still a WPF application. They are both XAML-based, so there is some limited ability to share resources.
If you are designing an application, select the technology that is most appropriate to the problem and the target audience. Keep in mind that while Silverlight runtime installs are growing fast, they still lag far behind others. Some people flatly refuse to install it. WPF apps can be distributed like desktop applications with an executable.
Update: In my experience, WPF XBAP applications don't behave well in browsers that aren't IE.
SL 4 can work in an out of browser mode. WPF has the XBAP (XAML browser application). So in a way they are but consider the limitations you may encounter in your projects.
Regards...
Some user controls can be reused between the two platforms. But because of the very different ways Silverlight and WPF interact with their environments (WPF on local system, Silverlight in browser plug-in sandbox) not all of the code is fully interchangable.
It's theoretically possible, but would require extra effort to port. And each is best suited to its environment. Here's an interesting discussion from an MS forum:
http://forums.silverlight.net/forums/p/1178/4244.aspx
For the most part, WPF is designed to run on the desktop and Silverlight and designed to run as part of a web page.
You can deploy a silverlight application to a desktop and run it from there, but there is no way to run a WPF UI "on the web".
With Silverlight 4 you can create a full trust application that is installed in the same was as a WPF application.
This article has a walkthrough.
So in this sense you can replace WPF with Silverlight.
You can link to WPF XAML pages on the web. This page has such a link, but you need a plugin to view it. I wouldn't want to deploy a full application this way though & I think it's only individual pages.

Silverlight or WPF for a little winforms/desktop type application?

I have a simple WinForms type application (main form, couple of sub-forms, minimize to system tray with notifications showing here).
I was going to move to WPF however I'm hearing some people say go silverlight (out of browser).
Question - Which way should I go for a simple desktop winforms type app? WPF or Silverlight?
Tks
It depends on what features you need. If you must minimize to the tray, it'll be easier in WPF. Silverlight, however, supports notification toast for notifications. It's not trayed, but it still works well.
Also note that Silverlight doesn't have floating child windows, so if you need them, you'll need to go WPF. You can get close analogs with the ChildWindow control, but they must stay within the bounds of the Silverlight application as they are ui elements, not real hwnd windows.
Silverlight 4 lets you do almost anything you need using COM automation. However, resist using that for major functionality. If you're targeting just Windows, do a click-once WPF application, preferably WPF4 if your timeline permits it. Reserve COM automation for OS "light-up" functionality in otherwise cross-platform applications.
Ease of application deployment is one big factor which Silverlight has going for it.
Depending upon the requirements and audience for the program, WPF or Silverlight will have advantages.
If you are able to run a setup on the target machines then WPF will be an option. If you want to launch from a webpage then Silverlight is the way to go.
if it's an internal app sounds likes WPF + ClickOnce is possibly the better choice. Unless you have (for example) sales people on the road with diff browsers, OS's etc then an installable SL app that talks to a (WCF) service might be a bet

Are WPF more 'flashy-like' than winforms?

I just installed visio, and the installer almost seemed like it was built in flash.
The buttons kinda glowed when I hovered over them, and when I clicked on 'continue' the form phased out in a cool way.
I'm assuming it was built in WPF.
Anyhow, so are WPF more flash-like (visually speaking).
Do they have new properties where you can make forms phase out nicely/smoothly compared to winforms?
Disclaimer: I work for Microsoft. However, I don't work on Visio, WPF, CLR or Silverlight team. So, the following is my personal take on these technologies. If you want to quote me, don't do it implying it's the official Microsoft position. :-))
Update: Anything I say below about Flash/Flex/AIR might be wrong, as I have not worked with these technologies and what I know about them is based on what I read on the intertubes. :-) If you notice anything wrong, just shout in the comment and I'll correct it.
To the best of my knowledge, the Visio installer is not built with WPF. It's all unmanaged code; it's just people took a lot of care to make it really polished.
WPF is the new UI platform for building standalone applications for the Windows OS. It supports a declarative UI language - XAML, and related CLR types to program against. WPF is a different platform than WinForms, although it is possible to build applications that mix UI built with both. WPF supports a lot of things that WinForms does not, like bitmap effects, animations, control styling and so on and exposes them both in XAML or through code. Also, WPF relies heavily on vector graphics, as opposed to the pixel graphics in WinForms. In short, WPF is quite powerfull and allows building very snazzy UI. (Don't take my word for it, though, as I am biased; go check around for what people are saying about it or buiding with it. :-))
WPF and WinForms do not compete with Flash/Flex. WPF and WinForms are both UI frameworks for building standalone client applications. As far as I know, Flash/Flex are frameworks for building rich internet applications - RIA (though lately people started interpreting this abbreviation as rich interactive applications).
Adobe did come up with AIR about half a year (or maybe a year) ago, which allows building standalone client applications, so you could say that Adobe is trying to position Flash/Flex/AIR to compete with WPF. Of course, that's my take on it and I doubt Adobe's official positiong is anything like that.
If you want to compare particular MS technnologies with Flash/Flex, take a look at Silverlight - it's the MS RIA platform.
Silverlight is related to WPF in the sense that they share XAML and the corresponding CLR types. Silverlight supports only a subset of what WPF offers, though, as it is not targeting Windows OS only and thus is limited by the fact that it has to be portable.
Quick update to reflect the changes in the year since I've written the answer :-)
With Silverlight 3 shipped, SL and WPF are getting even closer and sharing bigger set of supported features. In addition, most of the new XAML controls are built for platform at the same time. Thus, SL/WPF are getting to a point of singularity...
Also, SL 3 supports out-of-browser applications. In that sense, SL is not only starting to compete with Flash/Flex, but it is also encroaching on AIR's turf.
And no, I still don't work on the WPF or Silverlight team. :-)
WPF is being used as a replacement for WinForms, and as a competitor to Flash in the form of Silverlight. WPF consists of an entirely new object model that sits on top of DirectX (at least the desktop version). You can create WPF windows, controls, etc, entirely using C# or another .Net language just like you can render WinForms. However, Microsoft has also created a markup language called XAML (eXensible Application Markup Language). Nodes in an XAML document (XML) map to objects in a similar fashion to the way ASP.Net maps to web controls. XAML typically exists in a .Net project alongside a code-behind style C# file (or VB.Net or whatever). The C# file interacts with the objects generated by the XAML. This is fairly consistent with the "graphics via markup, logic via code" model that Microsoft and others are pushing.
One of the overlooked features when discussing WPF is the completely awesome data-binding that Microsoft wrote for WPF. The new data binding framework is a quantum leap beyond Windows Forms 2.0 data-binding. Microsoft added a couple of new interfaces that make it much easier to make an object or collection emit data-biding events properly. They also provided a very rich set of data-binding classes. You can bind anything to just about anything else. You can bind one-way data to control, control to data, two-way control to data and back, control to control, etc.
Back on the graphics side of the house, WPF makes it fairly easy to make an existing control look like anything. WP lets you compose your own template for what a class of buttons should look like, or one button, or all buttons. Or radio buttons. Or labels. You get my drift. Imagine if CSS included the ability to define what an input button would look like using other HTML controls.
They also provide a number of layout controls. You can continue to use exact positioning like in WinForms, or you can leverage of variety of techniques to make your window act more like a web page that grows and shrinks with resizing, etc.
The downsides: It is too easy to create spectacular effects that crawl on slower machines. Some of the graphics do not take advantage of hardware of graphics cards, though Microsoft has incrementally improved support for this. I believe when 3.0 first came out drop shadows were rendered purely using software. I think 3.5 or 3.5 SP1 changed it so that WPF would utilize graphics hardware for the task. Microsoft has said they will continue to enhance WPF in this fashion.
WPF is .Net 3.0 and above, which runs on XP SP2, Vista, and Servers 03 & 08. So don't plan on deploying WPF to a customer with Win2k desktops.
Summary: If you are doing desktop programming in .Net, you should be doing it in WPF unless you are targeting Win2k. You can avoid the downsides of WPF, and there are many upsides. Microsoft will probably throw away WinForms in some future release, or at very least you will stop seeing new features, etc.
As far as Silverlight goes, the betas for SL 2.0 look good. I think that Silverlight will require some wide-spread adoption. Microsoft has already tried to get this going. The NBC Olypmics site used Silverlight, and Major League Baseball uses it for its MLB.tv product. As soon as Silverlight gets a good install base I think you will see the Microsoft side of the development world starting swinging away from Flash and to Silverlight.
Edit after using Silverlight 3 and MVVM:
I have moved away from WPF and am doing a lot of Silverlight 3 development. But I think my comments here will still apply to the WPF developer.
I have been using the MVVM pattern in my app (think MVC with a twist). The Microsoft Patterns and Practices team has released a set of libraries known as Prism that supports various aspects of MVVM. There are WPF and Silverlight versions. Take a look at MVVM and Prism if you are going to be doing WPF or Silverlight development.
You can do a lot of flash w/ Winforms, or with custom components. But if you want out-of-the-box bang-whizz availability, WPF is the way to go.
Yeah, I think the intention is to be flash-like, it seems to me that MS has set its sights on taking down Adobe.
The way I see it: WPF is to Flash as WinForms is to Flex. WPF has more emphasis on vectors and states than on programming.

Can WPF and WinForms be mixed within an application?

Can both WPF and Windows forms controls be used within one application? How difficult or practical an idea is this?
It is fairly straightforward to host WPF controls in a WinForms app with an ElementHost adapter or WinForms controls in a WPF app with a WindowsFormsHost adapter. There are not too many resources on the web showing how to do either of these, however. In the process of learning how to do this for myself I quickly discovered the inherent symmetries between the two pathways. I distilled all my notes into an article comparing and contrasting these symmetries using a unique approach: the article is really two side-by-side articles, comparing every step in detail, starting from creating a user control in one technology to hosting it in an application in the "opposite" technology. My article, published on SimpleTalk.com in August 2010 is available here: Mixing WPF and WinForms.
For completeness, here are a couple good MSDN references, one for each pathway. In fact, the demo solution accompanying my article started from both of these:
Hosting a Windows Forms Composite Control in WPF
Hosting a WPF Control in Windows Forms
I believe there is a WindowsFormsHost control you can put in your WPF apps which will do interop back to WinForms code:
http://blogs.msdn.com/ivo_manolov/archive/2007/07/26/wpf-win32-interop-part-1-hosting-winforms-controls-in-wpf-windows.aspx
We hosted significantly complex WPF controls in an existing LOB WinForms app. It can be done, but we did have issues (some no doubt caused by the steep learning curve). These primarily had to do with loss-of-focus events not being fired when expected, and also keyboard navigation issues.
You can also use an HWNDSource and HWNDHost controls to embed WPF controls in a WinForms (or any Win32, really) app.
When hosting non-WPF content (Be it HTML, WinForms, or Win32 content), you will haveAirspace issues. This means you can't completely compost the WPF content with the hosted content. You also can't animate it etc. There are some interesting issues with respect to scrollviewers see here for more details and a fix also.
Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms. www.novamind.com's mind-mapping application is a successful mix of the two technologies.

Resources