Invoking a UI screen from within a class library function in WP7 - c#

I have recently started on Windows 7 app development, and I am stuck on the problem described below. Any help is greatly appreciated!!.
I am writing a WP7 class library function, which will be called from a Windows phone application. I want to be able to show a new screen to the user, after the function call has been made, invoked from the class library function. I also want this screen to be integrated with rest of the application UI properly. Like for ex., Clicking the back button on the UI screen, should take me to the UI screen that was present, before the call was made.
This WP7 class library has to be linked as a compiled library with the windows phone application. So keeping that in mind, I have following two questions.
1) Is it even possible, to launch a UI screen from a class library in Windows phone 7? If not, what else I could do here?
2) Is it possible to integrate this screen with rest of the application UI flow as described above.

Obviously you can include XAML pages in your library. To do that you have to include .pdb file which is generated along with the .dll for your library class. Copy both the .dll and .pdb file to your project and add reference to the .dll.

1) Yes. If you ever programmed Win32, then I understand your concerns. Handling UI in a dll was a bit problematic.
First to the class selection:
Popup class can be used to overlap current screen content. Its basic disadvantage is that it is not HW accelerated, hence unsuitable for complex screens or animations.
A better solution might be to store PhoneApplicationPage in your library (assembly). The result is the same as if the page was defined in the application assembly. This article describes how to navigate to another assembly.
When you navigate to another page (which is incidentally stored in another assembly), there is no shared UI context such as the main application window in Win32. The pages themselves are fully independent. URI of the first page is written in the manifest file. (Part of the xap file.) The application decides when to go to another page. Same as for browsers.
From the technical point of view:
Your class library produces an assembly (dll). This dll contains a) code (similarly to old good Win32 dlls), b) Xaml (exact copy of the Xaml code used in your library). It is the same as for your main assembly.
When you add a reference to the class library, that dll will be added to the xap file, i.e. to the installer. Go to your bin folder and look into the xap file. It is trivial as it is just a zip file.

Related

Unable to set start page (to windows form) in MFC application

At a broader level, I'm converting a MFC application (MFC 6.0) into Windows Forms application (Visual Studio 2013). I read certain blogs that describes that this conversion is possible. By this conversion I can re-use code written in MFC, only I will need to create UI. However I will need to understand the previous code and may need to re-write it a bit.
I got the motivation from here and here.
I have performed following steps so far.
Opened Visual C++ 6.0 project in Visual Studio 2013.
Build it successfully.
Then added CLR support to it, and fixed errors.
Added a Windows form, and added controls to it. As mentioned here.
Added functionality and build it successfully.
Now when I run this application, then it still point to old MFC window.
I'm missing certain settings which will change the rendering window from MFC to WindowsForm. What am I missing here?
Addition to that, I see problem with this approach as described by #Roger in comments, and I understand that. So, I wanted to know for any tool/utility which may convert legacy code into C#. Does such utility available?
TIA.
The code you are referring to seems suitable for amending a MFC application with a few forms as child windows to make use of .NET features. However, the main window is another story. You wrote the application is huge, so I suppose you don't want a simple form as your main window and rather have some kind of MDI interface in mind. If you replace the CMainFrame in the legacy MFC application, it just doesn't make sense to maintain an old CWinApp class. Anyway, if you are hell-bent on going down that path, you may want to have a look at an old CodeProject articel (.NET1.x, .NET2.x) to get a better grasp at the whole concept.
But as Roger already suggested, it would be a wise choice to find a nice GUI framework, perhaps even WPF instead of WindowsForms, and do a GUI rewrite -- especially if one part of the motivation for the conversion is to move to newer UI concepts. If your C++ program logic is well separated in your MFC project, put it in a COM server and make use of interoperability.

Extend a C++/MFC application with plugins in C++/MFC and C#

I wonder how to best develop a plugin framework where you can develop plugins with both C++/MFC and C#.
The Host Program is an existing program developed in native C++/MFC. To extend the functionality of this program, we have so far developed separate programs in C++/MFC and C# that run as separate applications or windows services. These programs are now communicating with the host application via files. This is obviously a rather clumsy method, and we therefore wish to bring them under a common plug-in framework.
Each program also has a separate management of settings. We therefore want each plugin to expand the settings window in the host application so that all settings can be managed in one place. How can we do that in a flexible and easy way?
(...) we therefore wish to bring them under a common plug-in framework. (...)
You can do that by creating a set of COM interfaces in a type library that you can wrap in a C++/MFC dll project. Then from either C++ or C# you can import this type library and create new COM classes that implement the predefined interfaces. Two disadvantages of these approach are: 1- That your main application will need to know the class IDs somehow to create instances of the COM classes. 2- Your plugins will need to be registered on the system or you will need to provide manifest files.
(...) We therefore want each plugin to expand the settings window in the
host application so that all settings can be managed in one place. (...)
This one is a bit more tricky, but you could try having a tab control with one tab for each plug-in, then pass the window handle of the corresponding tab to each plug-in during initialization, and then use that to place an ActiveX control on it. Creating ActiveX controls in MFC is well documented, and there is a sample project here for doing the same in C#: CSActiveX Sample

Resources in Winforms Application using CodeDOM

I have an application that deploys smaller applications.
Those smaller ones basically consist of an icon (not a form icon) and a notifyicon control that needs an icon as well.
My question is: How to embed resources in the small application and compile it using CodeDOM?
I need the icon from the "bigger" application (the one that compiles) as they would have the same icons.
Thank you in advance!
If what you are asking is how to embed resources in an assembly built with CodeDOM (which is the only thing it will do, w.r.t. resources) then see http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.embeddedresources.aspx.
If what you are asking is how to create .resource files programmattically, this has nothing to do with CodeDOM (i.e. it's not code and not an executable). But, possibly http://msdn.microsoft.com/en-us/library/xbx3z216.aspx will point you in the right direction/

Writing Control in Windows phone

I am trying to create a new Control (Let us for now forget about UserControl or CustomControl).
I open a Windows phone Application project in vs2010 and then add a new item Windows phone Control Library and then I use it in my phone application.
Everything works fine. Now if I want to create a windows phone control to be used in another application how should I be going about it? New application means a separate new solution.
Phone Application1 -> Have my own control inside the solution and hence I am able to use it.
How can I use this same control in another new solution?
I am not sure if this has been answered before. Does any solution already exist?
Cavet:
I tried creating a new Windows phone Class Library in a vs2010 instance but it didn't work because it didn't had a xaml form. When I tried to manually include it and write the logic it build successfully but now even if I include the dll of this project I don't get the control in the toolbox. This process does not make much sense to me as I am creating a class library and not a control but still wanted to give it a try.
To show controls from your assembly in the toolbox, you should do design-time assembly. You can look at these articles for the beginning:
Link2
Link1
It's not easy and perhaps you can live without that if your control assembly is not a commercial product. To use any control from other assembly in application:
add project reference to your control assembly
include xmlns namespace attribute corresponding to your assembly to any page of your application. Just start typing 'xmlns=' near other xmlns definitions in the page header and VS intellisense will show you the list of available namespaces. Choose the needed one and then set namespace alias to use on the page. It should look something like xmlns:myNamespace="clr-namespace:MyAssembly.Namespace.;assembly=MyAssembly"
insert control from your assembly into page using xaml editor
now you should be able to see your control in xaml designer and edit its properties from the property grid
.
I am not sure if the above mentioned method would solve the case, because as far as I have seen it is not possible to create a Windows Phone Control Library in VS2010. So this is what I did..
Created a Windows Phone Control Library and write my own custom control.
Build the project.
Back to Vs2010, added the reference to the control in the app in which I wish to use.
As simple as that. I don't know why it was initially a little bit confusing (perhaps I would have got confused with the binding and stuff). Anyways its quite simple though. Thank you for the reply.

Enable Visual Styles for a Class Library

how do I enable visual styles when my project is a class library and it's being loaded into a program that does not have Application.EnableVisualStyles() set. I have been struggling with this for 2 days now. This is in C# (I've seen some examples for older C++ and some things that may work for VB, but nothing has been clearly laid out for C# and if it's even possible).
I have tried to run Application.EnableVisualStyles() from my Class Library before creating any controls, but it seems that needs to be done before an Application.Run() is done, and I don't have control when an Application.Run() is called since this is going into a 3rd party app as a plugin (VMware's Virtual Infrastructure Client).
I have tried to create a manifest file and after compiling the class library I link in the manifest file to my ProgressBar.dll with:
mt.exe -manifest ProgressBar.dll.manifest -outputresource:ProgressBar.dll;2
Except this doesn't work. If I make a dummy Application that uses my ProgressBar class library and link the manifest to that Application's exe, then the visual styles come up (basically it's doing the long way of specifying the Manifest file in the Project Properties, Application section).
Right now my buttons look ugly, but the biggest thing that is irritating is that the ProgressBar control doesn't work in Marquee style. I'm very soon going to have to resort to making my own Marquee-style ProgressBar or just throwing in an animated GIF in it's place. With regards to the buttons, I guess I can start using Infragistics buttons in order to get a more consistent result.
Please and thanks as always!
How can you be sure that there are no controls created yet when you call Application.EnableVisualStyles? Created does not necessarily mean that the controls are also visible on a form.
Since you are working with a closed 3rd-party component I would invest my time rather in creating my own controls if the look and feel is that important.
You'll have to use the OpenThemeData Win32 api in your control:
MSDN: Using Windows XP Visual Styles

Categories

Resources