Creating portable silverlight user control - silverlight

I'm trying to make a portable silverlight user control to be used in 2 separate projects: one is WP8 project, and the other is Windows Store.
In both of them I use xaml/C#, and based on silverlight. But the silverlight control I created works only in WP8 but not in Windows Store.
cannot convert from 'Controls.ProfileBox' to 'Windows.UI.Xaml.UIElement'
Is it possible to create a silverlight class library that has a control usable in both projects?

How do you compile your different project?
The easiest way to share your code between framework in c#/xaml is to compile the code in the required farmework:
You need to use the "Add as link" feature (Right click project -> Add Existing Item -> Change "Add" Button to "Add as link"). This way you have only one version of the source file, but you have N project for the N framework you want to compile.

Related

How can I create a Windows Control Library project in Visual Studio?

i was trying to complete a tutorial on custom controls and all of the tutorials that ive found say that you have to choose a project template called "windows control library". I don't have that template as an option! I am using VS2010 professional. Any ideas?
The "Windows Control Library" project template is used to quickly get started creating custom controls for use in Windows Forms (WinForms) applications. It creates a project that is automatically populated with the necessary references and files.
To create a new project of this type, you first have to pick one of the .NET languages—it doesn't matter which—either C#, VB.NET or C++/CLI.
Then, select the "Windows" category to narrow down the scope of the project types that are listed.
Finally, select the project type called "Windows Forms Control Library".

Is it possible to share code between a Silverlight web app and Windows Phone 7 app

I have a simple Silverlight app that I want to run on Windows Phone 7 almost exactly as is. I've created a new Windows Phone 7 project and when I reference the Silverlight app I get a warning that says "Adding a reference to a Silverlight project might not work properly. Do you want to continue?".
If I continue and try to run anyway, the WP7 project never starts or sometimes I get "AG_E_PARSER_BAD_TYPE error" and it points to the line in the xaml I used a control from the Silverlight project .
The code between these two projects is about 99% the same. Is there another way to reuse code then what I am trying? Or how can I get this to work?
I'm not that familiar with the difference between the two platforms, but you can link the code files into a different project without duplicating them. Add existing item, and click on the down arrow next to the 'Add' or OK button. Choose Link.
The typical way of achieving this is by using a pattern like MVVM which will allow you to define a common model and viewmodel layer (perhaps in a separate project) the defining a different view layer that references that common project.
You said it yourself, you will only share MOST of the code, not all of it, so you will, at least at some time, need to create device/front-end specific logic and layout.
Rather than add a Silverlight [presumably class library] project to your WP7 app, try creating a WP7 class library and then link the files from the silverlight library. You will still only have one copy of each file but all your libraries will be built appropraitely for the platform they are running on.
This may also help you identify the cause of the problem. The error AG_E_PARSER_BAD_TYPE suggests that you have a type in the XAML in your Silverlight project which isn't supported on the phone.

How to call method written in C# class library from Silverlight application(xaml.cs file)?

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.

Reusing a Control in another Windows Forms Project

I've got lots of web experience but am a total novice when it comes to Windows Forms so this might be easy to answer:
I have Project1 which I've added a reusable control to which allows filtering and searching of data and presenting results.
I now want to use the same control in another Project.
When I open Project1 and select my form the reusable control appears on the toolbar so I can drag it onto any form in the project, but how do I get this to happen in my new Project?
You can add a reference to the (binary) control:
menu Project/Add Reference/tab Browse
Then it should turn up in the Toolbox (menu View/Toolbox).

putting some WPF windows in DLL

I have a WPF project, and there is one dialog that I will re-use in different applications. I want to put it in its own DLL, but when I use the New Project wizard in Visual Studio 2008 it only lets me create WinForm C# DLLs. Am I missing something?
You should be able to create a WPF Custom Control Library project.
To add to this, this particular project does not actually show up unless you specifically choose Classic Desktop projects.

Resources