Change WinForms application language at runtime - winforms

It is possible to change the language of a localized WinForms application at runtime? I tried using the method described here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=174 but for example the control tooltips are not refreshed. I'm sure that I might face other problems too.
Is there any safe (0 bugs) way to do it?

Guy Smith-Ferrier wrote the book on .NET internationalization (literally), and here is the code for his solution: http://www.dotneti18n.com/Downloads.aspx
In my experience it doesn't work perfectly, failing on DevExpress controls for example.

Related

How to use the WinRT SwapChainPanel control in a WPF window?

I added references to WinRT dlls to a WPF project and I want to use SwapChainPanel inside of a WPF window.
Is it really possible? For now I cant get it work.
The NuGet package description for Microsoft.Toolkit.Wpf.UI.Controls mentions a SwapChainPanel but I have not found any samples using this control in WPF.
SwapChainPanel : Provides a hosting surface, where Microsoft DirectX swap chains provide content that can be rendered into a XAML UI. A SwapChainPanel element is a key component for an app that renders Microsoft DirectX graphics and then presents those visuals within a XAML page.
It's not currently officially supported - might require some private APIs in Windows, though since Stardock could implement its ModernMix - there might be some way to get it working. The thing is though - you don't have to do that. You can render content with DirectX to a WPF window in other ways. I haven't done that and it might be quite a bit of work to do, but so is anything in DirectX. You can look into DirectComposition or D3DImage class. Perhaps the article on using Direct2D with WPF can be a good sample solution.
You dont have to, as says Filip Skakun, but you can ! Just give a try to SlimDX or SharpDX. They're DirectX's implementations in C#.

FsharpCharts for silverlight / f#

This might be a stupid question, but there are soo many combinations of approach (wpf, silverlight, winforms, html5) with incompatibility at mscorlib level, that I got completely lost.
I would like to be able to have a few windows mainly displaying realtime charts.
Probably with interaction among the windows (click in one, pop and display a new windows)
If it can be viewed on the web, perfect.
But I dont want to have to deal with another layer of nasty stuff for those features (like having to setup some "WCF" on a "IIS", kill me first)
In the end I was thinking of using FSharpChart on Silverlight.
Is that possible and/ or the best option ?
Thanks for your suggestions
update
I see that system.drawing which fsharpchart relies on is not silverlight supported..
Try Dynamic Data Display instead of FSharpChart. It runs on Silverlight: http://research.microsoft.com/en-us/um/cambridge/groups/science/tools/d3/dynamicdatadisplay.htm
It's not as F# Interactive friendly as FSharpChart, but you can easily wrap it in a handful of functions to make it more usable

Migrate application from WPF to Silverlight

I saw a lot of question on this topic and it took me some time to decide whether or not I would write another one ... but I think my question is a bit more complicated ... so here we go.
I'm currently working with a WPF application using MVVM.
The application is built with:
WPF
Prism V2
Ideablade (devforce) to access a database
Avalon dock for the docking feature
Telerik for the grid component
Views and ViewModel are generated with .tt file.
Views are generated in xaml (for WPF) files.
I know that:
Telerik has Silverlight controls
Using Prism V2 will probably help me doing a Silverlight version of the application
I don't know:
If the usage of devforce can be a show stopper
If the usage of avalon dock can be a show stopper
My question:
Appart from generating xaml for Silverlight ... where do I start ...
----EDIT----
Please, avoid any comments like "Silverlight will die" or "Silverlight xaml is a subset of WPF xaml".
It is a proof of concept and should be made using Silverlight. For the xaml, I can modify the application to use only simple ui element that can be both in Silverlight and WPF.
Depending on how you actually used Prism and other frameworks this can be a lot of work or quite easy.
I'd start at the 'bottom' because I'd expect the Models and ViewModels to be quite portable, at least that is what I have experienced so far. She fact that Silverlight more or less forces you to write async code everywhere might encourage you to investigate in (yet another) framework such as Rx
The Views could be quite a hassle; you will have to find controls that provide the same features that you are using in WPF, build them or invent something new. That can be a lot of work.
Another thing to consider is when your WPF app relies on many desktop features you might consider creating an Out of Browser Silverlight App.
As with any project try to find areas that will probably need a lot of attention and do those first; it's a waste of time to get a lot of stuff working to find out later that you will have to replace it because of an impossibility elsewhere.

C++/CLI, XAML, and event handlers

I'm new to the Windows world, and I think I'm getting lost in the weeds on a problem. I'd love some advice from people with experience with C++/CLI and WPF and XAML.
I have some win32 code, and I need to run a WPF GUI. I found this MS walkthrough sample, which uses C++/CLI. I adapted it to my purposes, and it works great.
Next, I wanted to rip out the programmatic WPF stuff and use XAML instead. This is so I can hand off the XAML to a designer person and take myself out of the UI design loop, where I most assuredly don't belong. After reading the "WPF Interoperation Projects" section of WPF and Win32 Interoperation on MSDN, I decided to go with the XamlReader::Load option and load uncompiled XAML at runtime. My XAML markup is a Canvas UIElement which I programmatically add as a child of my root Grid C++/CLI element. This works great.
Now I want to add event handler to controls in the XAML. This is where I have started to run into trouble. I'm sure that my general ignorance of the Windows world is 95% of what's killing me here.
I started with Rob Relyea's page outlining the various XAML-and-event-handler options.
I decided to try compiling the XAML as a C# DLL. It's basically the same XAML as what I used in the runtime Load case. I instantiate the object and programmatically add as it as a child, just like before. But ... I get nothing but a black window. No exceptions get thrown either. I'm baffled.
My question is, am I even headed down the right path? The page on XAML-and-event-handlers says you can use event handlers defined in uncompiled XAML in .Net Framework 4. Should I bite the bullet and just go to VS 2010 (I'm presently on VS 2008) so I can use .Net Framework 4 and just stick with uncompiled XAML? Are there any gotchas with doing things that way?
Or, if you do think the compiled C# DLL is a reasonable path, do you have any ideas on how I can debug the problems I'm having?
Or, is there a better and completely different approach?
Thanks in advance for your advice.
Polly
I think the right answer for this depends on some issues that only you can decide, but I'll start with the assumption that your C++ code base is big and complex enough that it is worth preserving.
Beyond that the next decision point is do you have UI (perhaps GDI) code in the C++ your preserving or only non-UI code. If you are attempting to preserve only non-UI code then I would consider pushing more UI responsibilty into C#. Perhaps you go so far as to build your views, event handlers, and maybe even view models in C#. This will enable you to take better advantage of the VS tooling.
If you've got extensive UI code in C++ to preserve then your current path makes a more sense. I don't think it will be impossible, but you'll have quite a challenge ahead of you. The key example here is Visual Studio 2010. It is the premiere example of a mixed application and has GDI and WPF side by side unlike any other app I've ever seen or heard of. There is a series of blog posts that I found pretty interesting that describe some aspects of what the Visual Studio team did to achieve this integration at The Visual Studio Blog.
I also came across this video Henry Sowizral on Refacing C++ with WPF in Expression Design that I have not seen myself, but discusses putting a WPF UI on top of an existing MFC C++ app.
Good luck.
I don't have any specific advice on the first part of your question other than to say that putting more responsibility in C# would allow you to build a small stub app if necessary which could go a long way toward diagnosing problems.
Thanks to everyone for the responses. On the matter of getting stuck on the C# DLL, I found this C++/CLI sample: http://msdn.microsoft.com/en-us/library/aa970266.aspx. Using that, I found my error, and was able to load the WPF without problems.
However, the whole motivation for loading the C# DLL was that I had understood that that was the way to attach event handlers programmatically. Following AresAvatar's suggestion, I found that I could use FindName to attach the handlers -- both within the C# DLL, but it also worked with my original loose-XAML approach. So, I didn't need the C# DLL after all!
It's all working nicely now. Again, thanks for all of your help and suggestions.

Anyone with experience of targeting Silverlight & WPF?

Is it possible to develop against Silverlight and WPF using the same source code? Maybe using some #define blocks where it is necessary.
Theoretically it should be doable. It's not a big problem for the code. However, you'll have to be very careful with XAML and use only the intersecting subset of WPF and SL (1), as there's no #if/#endif for XAML.
(1) Contrary to the common belief, SL is not a proper subset of WPF. It has some features that WPF does not have, though these are being worked on.
Incidentally, PRISM (the composite application block from patterns and practices) now supports Silverlight and there's a C9 video with a quick sample on using code in both WPF and Silverlight.
I think if you stick to MV-V-VM (or something along those lines) then a lot of your backend code will be reusable, but the XAML itself might need to be forked if you want a full on "rich" experience, unless you are willing to use the VSM beta for WPF.
I have no experience on that but I have used a component that targets both WPF and Silverlight environment with the same code (there are only few differences).
The component is Chart from Visifire and it's Open Source
Maybe you can take a look into it
You can use Visual Studio file linking to include classes from WPF projects in Silverlight - but only if they don't do any UI or XAML based stuff (as this is where you will usually find inconsistencies between the two)...
So keep it to business logic etc.
Flashcards.Show application is a great example of this WPF/SL/WP7 code sharing and cross platform possibilities.
http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/03/03/flashcards-show-planning-a-cross-platform-solution.aspx
Concept of cross platform is pretty simple because everything works on .NET and a similar XAML binding system. My advice here is to invest more time on architecture of the app in terms of MVVM and other abstraction to segregate the platform dependencies. So that a major percentage of the code can be re-used across while some of the XAML might need to rewrite depends on the visual complexity of the app in different platforms.

Resources