WPF locbaml-ed application and runtime language switch? - c#

i wonder if there is a simple solution to change language of a wpf application during runtime. i used locbaml to globalize all the resources. Setting the Current Thread's UICulture in the App-constructor works fine, but when i try to chang it a little bit later, i doesn't reflect the changes anymore.
This was actually quite easy with winforms, but i have no clue how to solve the same problem with wpf.
any ideas?
regards
j.

No.
Once you load an assembly and it is bound to your application, you can not change classes in mid-work. You could create a bootstrapper assembly that loads the current language and when you change the language you close and re-open your application automatically, but I doubt that's what you want or need.
What I did on one of my projects was create a globalized application framework using converters, etc. You can see some of the problems I ran into here and especially this post which shows how it looked. HTH if you decide to go the same way as I did.

Related

Can a component be added/registered after run time?

I would like to be able to do the following and am not sure if it is possible...
I would like to have a WASM Blazor application that can have components added after the application is compiled and running. For example, if I created a simple application that displays photos and give the user the ability to change the style by choosing a different component. Please ignore the fact that there may be better ways to "style", this is a simple example to illustrate my goal. Maybe these "style" components are listed and available for download but are NOT preloaded. I would like the user to be able to choose a different style and then, and only then, download the dll for the component from a remote repository and load that component into the running application so that it is available to render. I have looked into DynamicComponent and that shows some promise. But it seems as though most of the information I can find about this has the need to declare those types up front before compilation.
Does anyone know if what I am attempting is possible? Am I on the right track? Thanks!
You can hold off on loading assemblies until they are required using Lazy Loading, give this a read:
https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-6.0

Static resources in WPF in pluggable application

I am currently working on an enterprise WPF application and I am experiencing some issues with static resources: globally defined styles and converters.
The application works this way:
There is a shared host WPF application that is used as host for components developed by different teams (it's a PRISM application and MEF is used for importing plugins)
Each team can add plugins by creating new dlls, but cannot modify other teams' dlls
No changes can be made to the host application
My team is in charge of few plugins and we need to add more functionalities but we are wondering what is the best way to solve our problem.
In a simple (standard?) WPF application, we would have styles defined in the App.xaml file and all the xaml UserControls or Windows would be able to link to them at design time easily and of course at runtime.
But now, while I managed to get the styles to work during runtime, I cannot have them working at design time and it is causing two major issues:
I cannot see how things would look like in the IDE
When I reference a converter the IDE complains but I have no way to know how wether it will work at runtime or not.
How do I get StaticResources to be imported and, at the same time, work in my IDE?
If not possible, what other strategies can I adopt to overcome these issues?
If I understand you correctly you want to use your "Design" tab in Visual Studio to see style changes and check the look and feel of your WPF application.
If that is the case, I will disappoint you but I haven't met any WPF developer yet using the 'Design' instead of 'XAML' view to make changes etc. in more advanced applications. Unfortunately the "Design" view has many flaws, doesn't display the Views properly, has problem with static resources converter and what is more it is always resource hungry.
The way we are working with WPF applications is building them and inspecting the problems and changes using a Snoop utility to investigate the application, binding errors, style problems, etc. I have never seen a way to use the build in "Design" view without many flaws, hacks and performance issues.
What is more, you should write a fake host application so that you will be able to run your plugins without the need of running the main app (if that is a problem for you)

Can I dynamically add a user control to a silverlight application without recompiling it?

I have a silverlight application with several menu buttons, each of which opens up a user control in a center "work space" area. It works fine. Now what I'd like to do is make some more user controls, compile them into a dll, and through say, a configuration file, have the silverlight app add a new menu button and make it make one of those new controls appear. The difficult part is, I'd like to be able to do this without recompiling the silverlight app. I'd like another developer to be able to make a user control that does some things, compile it into a dll, and drop it into the silverlight directory with some changes to a config file to get the main app to load it in. Is there a way I could do this?
Since noone else has replied yet:
What you want to do is reflect classes form a third-party dll at runtime. This is possibly too big a subject for SO, and all I can really recommend is looking up examples of it, and maybe the msdn section on it.
You'll also want to look up serialization and deserialization in C# and silverlight (this question might be a good start).
Sorry I can't be more help than that, but hopefully someone more experienced will weigh in with a useful article or some such.
Good luck :)

.Net switching control suits

I have developed a windows form project using Telerik controls. Now for some reason I've to switch to Syncfusion controls. What is the best way to switch to new controls? Do I have to drag and drop all the stuff again..?? Or is there a any other option which may be less time consuming.
It's very time consuming. It's not only a matter to change the controls. Probably they are totally different in terms of events, costants and worse in terms of functionality. You will need to test all of your code and probably rewrite the UI interaction methods.
If you really need to do that, take your time, and use a version control system to create a branch for the new version while maintaining support for the old version still using the Telerik controls
You could just change the references in your *.Designer.cs files, but you'll probably run into errors when the Designer file attempts to assign properties that have existed in the Telerik controls and don't exist in the Syncfusion ones.
This approach will probably be less work than remaking every form, but it'll still take some time.

Adding GUI components to a precompiled application

iI there any way to add a GUI component to an application which is already running?
I.E. Add an extra tab into a third party GUI?
I have a third party application where I need to add an extra tab into the tabbed interface (or even a button to link to a new form).
I can see the UI components in UISpy and Spy++ but Can't see a way to alter or add them...
Any ideas? Maybe altering the memory?
Update:
The application I have created to wrap around the third party app is .NET but the third party app is written in VB6
I suppose it's entirely possible with reflection, with the aid of Reflector, assuming it's not been obfuscated. Explore around the reflected source until you find the class of the form, and the instance of the form that you want to modify, then you can invoke the Controls.Add method, or anything else you need to, with reflection. But unless you know exactly what you're doing, you could run into some unexpected behavior from the application.
You can use ResHacker.
http://www.angusj.com/resourcehacker/
Basically, each GUI form is saved as a resource inside of a particular Windows executable. ResHacker has a built-in GUI editor for editing "Dialogs" (as they are referred to in ResHacker).
I assume it's a .NET WinForm app. If you do not have the source files and the app isn't too big, you can try 'decompiling' it and add in your code to become a new app.
I'm a great fan of Lutz Roeder's Reflector which generate code from the CLR codebase.
Here's a link to his tools. http://www.lutzroeder.com/dotnet/
Update:
darkassassin93 is right, hopefully the app is not obfuscated :)
You should have strong reason for doing that.
I think you can start with Add Tab using pure WinAPI and TabCtrl_InsertItem Macro
If you have HWND of TabControl you can try to add your own tab. with TabCtrl_InsertItem. Although i don't think it's possible to do that from another process. But you should try.

Categories