putting some WPF windows in DLL - wpf

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.

Related

Creating portable silverlight user control

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.

Loading a WPF form into a MFC application without /clr

I am trying to integrate WPF into a legacy MFC application. I am unable to include the /clr switch to mix managed and unmanaged due to the restrictions of other projects in the solution. I need the WPF window open up as a child window in the main MFC application. I have been investigating different ways for the past two weeks but have hit roadblock with every implementation try. If anyone has successfully integrated this type of implementation, I would appreciate some direction. I have been able to integrate with a Win32 app, but could not translate this to an MFC app. Thanks everyone.
I believe that WPF requires .NET, therefore what you need is to create a separate DLL or EXE for the WPF parts. hat new project could be the container for .NET code and your main MFC would launch this separate project.
You can write a WPF front end that launches C++ apps with the desired command like switches, similar to what Visual Studio 2010 is doing to compile your code and show the results in the output pane. In this way you can avoid having to hack message loop code to support both frameworks .
You may show your Dialog using a COM interface

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".

How can I make Visual Studio 2010's "Add User Control" create a WPF control?

I have a class library that I created using the "Class Library" project template. If I right-click on this library in Solution Explorer and select "Add > User Control", Visual Studio adds a WinForms UserControl. That's not what I want -- I want "Add > User Control" to add a WPF user control.
I've already added references to the WPF assemblies (WindowsBase, PresentationFramework, and PresentationCore), and I already have some WPF UserControls in this library, and everything compiles. My library does not have references to the WinForms assemblies (System.Drawing and System.Windows.Forms). But apparently the proper references are not enough of a clue for Visual Studio, because when I try Add > User Control, it adds the WinForms references to my project, and then creates a WinForms UserControl.
I can add a WPF User Control to my WPF Application project, and then move it into my library. But that's a pain, and I'd rather have it work properly in the first place.
I think I'm probably missing some kind of arcane XML element in my .csproj file that tells Visual Studio which designer to use by default, and if I add the right XML element with the right cryptic GUID, it will start working properly. If I could create a new WPF Control Library, I could probably compare the two project files and figure this out. However, I'm using Visual C# Express, which doesn't have a template for a WPF Control Library project, so I'm out of luck there.
What do I need to do to my Class Library's .csproj file so that VS2010's Add > New User Control will add a WPF UserControl?
There are sub-projects class ids in the project file that affect the Visual Studio context menus and how the project behaves in general. The easiest thing to do is to recreate the project as a:
WPF User Control Library
instead of a "Class Library". It is possible if you already created the project to edit in the sub-project class ids by hand by opening the ".csproj" file in a text editor such as Visual Studio itself but its easy to cause more damage than you fix that way.
I believe but haven't test that another type of library will also work:
WPF Custom Control Library
which is intended to hold other types of controls than UserControl objects but being a WPF sub-project type the context menus also work correctly for the use case you are describing.
Edit:
For completeness, I've just tested how to manually add the sub-project GUIDS. Add this line to the first PropertyGroup in the .csproj file:
<PropertyGroup>
...
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Not tested with Visual Studio Express.

Exception when add Silverlight dll in WPF application

When i added the silverlight dll in the wpf application , i got the following exception.
Could not load file or assembly "System.Core, Version=2.0.5.0". The located assembly's manifest definition does not match the
assembly reference.
This is happening only in VS 2010 professional Beta 2.
You cannot use Silverlight directly in a WPF application, as they do not use the same version of the .NET Framework, thus the error message
Could you give some more details on your scenario ?
If you have a WPF app, you have more than what Silverlight can give to you.
If you are building a solution with multiple products, and one is WPF for the desktop, one is Silverlight for the Web, you need to create 2 different projects in VS.
Take a look at the source tree here:
http://expressionblend.codeplex.com/
Specifically, the Expression.Samples.Interactivity.Design branch.
This shows a few examples of how to put in property editors for use with Blend. I'm not sure if the same concept is transportable to the Cider design surface, but heck, Blend is nicer for pure XAML editing anyways. :)

Resources