开发者

How to compile a WPF application into a class library and start the application when needed

I am wondering how to compile a WPF application into 开发者_JAVA百科an independent shared class library(dll)? Any sample?


  1. Solution Explorer -> Right Click on "MySolution" -> Add -> New Project -> WPF User Control Library
    Add your controls there and use from any other application.

  2. Convert your current project to dll: Solution Explorer -> MyWpfApplication -> Right Click -> Properties -> Application Tab -> Output Type = Class Library

  3. Or you can add references from other Applications to your existing project even if it's exe. (Controls are still available)


A library is not an application, so we can't convert a WPF application to a dll and expect to be able to run it independently.

One workaround might be to change the projects output type to "Class Library", then create a new WPF application which hooks into the dll.

To make the new application hook into the dll, first add a reference to the dll, then edit App.xaml and change StartupUri to a pack Uri pointing to the dll.

<Application x:Class="WpfApplication13.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="pack://application:,,,/ReferencedAssembly;component/MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜