We have a VS2012 solution that contains two class library projects, one that produces a Silverlight DLL and one a standard .NET DLL. The class files are shared ("Add as Link") between the two projects.
The upshot is that they both contain a WPF/Silverlight control that inherits from Canvas that we then use within Silverlight and WPF applications.
We are now looking at using the same component within an app to be used on a Microsoft Surface RT. How do I go about building a DLL that can be used like this?
There's no reason you couldn't do it the same way, you are already doing it if WPF and Silverlight: just create a Class Library (Windows Store apps) project and add existing class files as links to it as well.
You can use conditional compilation symbol NETFX_CORE when you need different code for Windows Store apps:
#if NETFX_CORE
// Windows Store specific code
#endif
Related
As simple as in the title, I'd like to know how to use a ProgressRing on my gui. I can't figure out how to import the Windows.UI.Xaml.Controls namespace in which seems to be located.
Thanks!
Eugenio
I don't think you can add a reference to a Windows Store Apps DLL to a WPF project, they are built against different versions of the framework.
You could however use a ProgressRing from a different WPF targeting DLL; MahApps Metro has one https://mahapps.com/docs/controls/progressring (source is on github so you can just take what is needed without having to jump fully into the metro style)
Or you could implement your own following a tutorial http://henryzhu1997.wordpress.com/2013/06/18/creating-a-progressring-for-wpf/
This is a question about design approach. I have limited COM experience and a little WCF experience. My constraints are given by the application environment, but I have some design flexibility.
From within a VB6 dll, I need to start, and communicate with, a WPF application. The WPF application is currently an exe, but I could make it a library if that helped. I would like to provide two way communication between the VB6 dll and the WPF application. I have some flexability to adjust the design of the VB6 dll.
I'm developing C# using in VS2010 and .NET 4.
How many components should I use? Can I start the WPF application In-Proc with the VB6 dll? Should there be a third component between them? Can COM+ play a helpful role? Do I have to make the entire WPF application COM-visible? Is there a down-side to doing this?
I'm looking for a design approach that I can prototype. I'm willing to research the details.
I would
Create a Web Service from the WPF application, using WCF. I would abstract out those aspects of the WPF application which should be accessed remotely. This would explicitly not include any of the user interface code.
I would create a simple class library project, and use "Add Service Reference" to add a reference to the WCF service.
I would make the methods of the class library COM-visible
I would call those methods from VB6
This has the benefit of removing any considerations of user interface from the equation.
Out of the options available I like the COM option more than the 'start another process' option for the simplicity that the inter 'application' communication will be via method calls rather than WCF or anything similar.
I am assuming that your VB DLL lives in a window'd process and not a service or web application. You would only need to mark any exposed types as COM visible, that is the classes, their argument and return types.
You may have to wrap your WPF UI inside the windows forms ElementHost [1] but I'm not sure, try it and see.
I'm not sure if you saw this [2] in your search, it sounds do-able but unsupported, ok as long as you don't have too much going on.
[1] http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx
[2] http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7555ba6a-1359-4dfe-aa23-c31a8f121142/
I work on an application primarily written in VB6 but most of the recent code is written in .net with UI components built in WPF and some WinForms. Datasources for this application are WCF, MSSQL server, and a propritary unix based server. All the WCF calls are made from data access components referenced by the .net UI components.
You can host WPF in VB6 windows or other container controls. Start by getting the Interop Forms Toolkit and build shell user controls to host your WPF controls.
To be able to host WPF in these controls you need to build a WinForms usercontrol which contains a ElementHost, which you can set the content to your WPF usercontrol.
WPF Usercontrol inside an Element Host inside a
WinForms usercontrol inside a VB6 usercontrol or
window
The interop toolkit will want to build VB.Net code but you can do it in C#, although I have not tried this. The usercontrols created by the interop toolkit will be exposed as COM components which you can reference VB6 by adding them as components via Project > Components and then you will find them in the toolbox.
In terms of data sources (WCF, databases) etc, you should build all your data access in .net components referenced directly from the UI components, don't try to call back in to VB6 libraries, you will probably just create a mess.
In my application I also have a configuration section which I call from the VB6 application startup which sets up an IoC container for all the .net components.
From a best practice approach I actually would recommend rewriting your VB6 code to .net and putting VB6 out of the picture. If this is not an option then you have a number of options, my explanation is just one of them.
Can a Silverlight application call a method in a full .NET c# class library?
I am trying to add a Silverlight control to my Existing ASP.NET project where i used to add reference to my Business Logic Project and access methods from My UI pages of ASP.NET Web application. Now I have added one Silverlight project to my solution.
How can I use the already existing BL method which is in a C# class library ? When tried to add reference, it is saying that
"You can only add project reference to other silver light projects in the solution".
Should i give up ? Is there any way to get rid of this ?
A common method to achieve this is to build a silverlight library that links in all the files from your Business Logic library. This way the code is written once, and built twice. To link the files go to Add Files in Visual Studio and select the drop-down arrow on the Add button. Select Add as Link.
Alternatively Silverlight 4 and .NET 4 have binary compatible assemblies, so as long as the code in your main Business Logic library is fully Silverlight compatible you should be able to use the library as a reference there.
I'm getting started with Silverlight. When creating a new solution I have the option of creating a Silverlight Application or Silverlight Class Library. The Application option sets everything up for me but class library is quite sparse.
I'm trying to work out which one do I start with? Particularly I'm uncertain about when I would use SharePoint Class Library and what benefits/restrictions it has over Silverlight Application.
I'd like to write a control that I can put either a plain ASP.NET or Silverlight UI on top of, with both talking to the same back end.
The Silverlight Application template will create a shell UI with necessary project configuration to launch a Silverlight application. You have the option of creating an asp.net or plain html-based Silverlight application. The Class Library template, like the non-silverlight counterpart, is UI-less component that the Silverlight application can consume. You will not be able to reference regular class libraries, or sharepoint class libraries from a Silverlight applications as framework requirements are different ... Silverlight relies on stripped-down framework that is not compatible with full .NET release at this time.
So, in order to develop a Silverlight application, you need to start with Silverlight Application template, which then can reference any number of Silverlight Class Libraries, depending on your project layout or architecture.
If you want to write components that you can either snap an ASP.NET UI or Silverlight UI, you will need to create either a Class Library (for ASP.NET) or Silverlight Class Library (for Silverlight). You will not be able to reference Silverlight Class Library from ASP.NET, or reference Class Library from Silverlight. However, you can share the code between the different class libraries by linking source code files between them.
ib.
I have a Silverlight application that is built from a set of Silverlight class libraries. I would like to create a common Silverlight library that contains a set of resources used to define the styles used for all the Silverlight UI libraries. This would be simlar to the <Styles>'s defined in the node within App.xaml file.
Is this possible? And if so, how would I implement?
While this is possible using WPF (via Dynamic Resources, see this video and fast forward to 12:00), I don't think this is possible yet in Silverlight. The closest thing you have to this is the themes in the Silverlight toolkit. There is a comment on that page by the team stating that you can't change themes (or resource styles) at runtime in Silverlight 2:
unruledboy, We do not support changing themes at run-time as this is not an ability supported by the Silverlight framework.
So I think themes is the closest thing available right now.