Wpf MahApps.Metro无法加载Visual Studio扩展名中的文件或程序集

Wpf MahApps.Metro无法加载Visual Studio扩展名中的文件或程序集,wpf,xaml,visual-studio-extensions,mahapps.metro,Wpf,Xaml,Visual Studio Extensions,Mahapps.metro,我在VisualStudio扩展工具箱的XAML代码中使用MahApps.Metro控件。我通过NuGet安装了这个包,然后尝试将一个控件添加到我的XAML标记中。下面是代码片段 <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="h

我在VisualStudio扩展工具箱的XAML代码中使用MahApps.Metro控件。我通过NuGet安装了这个包,然后尝试将一个控件添加到我的XAML标记中。下面是代码片段

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:custom="http://metro.mahapps.com/winfx/xaml/controls" 
    x:Class="AutoDebug.MyControl"
    Background="{DynamicResource VsBrush.Window}"
    Foreground="{DynamicResource VsBrush.WindowText}"
    mc:Ignorable="d"
    d:DesignHeight="500" d:DesignWidth="400"
    DataContext="{Binding UserControlModel}"
    x:Name="AutoDebugWindow">

    <Grid Margin="15">
        <custom:Tile Content="Tile" HorizontalAlignment="Left" Margin="75,150,0,0" VerticalAlignment="Top" Background="#FF8B00BF"/>
    </Grid>
</UserControl>

但无论发生什么,我都会收到以下错误

PresentationFramework.dll中首次出现类型为“System.Windows.Markup.XamlParseException”的异常

其他信息:无法加载文件或程序集“MahApps.Metro,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件


我已经尝试过安装/卸载、删除/添加引用,但到目前为止没有任何效果。

这是因为编译Visual Studio扩展时,MahApps.Metro未作为引用包含在内

我不完全清楚为什么,但是如果您只在XAML中使用MahApps,那么编译的程序集中就不包含引用。您可以通过解包扩展名(它只是一个zip文件)并在ILSpy中打开程序集来检查这一点。在参考资料下,Mahapp将不会被列出

解决方法是在代码中的某个地方使用MahApps。最简单的方法是命名您正在使用的MahApps控件。这将为控件生成一个字段,这似乎足以使引用包含在程序集中

<Grid Margin="15">
    <custom:Tile x:Name="MyTile" />
</Grid>


您也可以在代码中的任何其他位置使用MahApps程序集中的对象(例如,您可以在
包的构造函数中创建一个新对象),但为其中一个控件命名可能是最简单的方法。

阅读quickstart文档,您应该能够使其正常工作:我已经按照步骤进行了操作。但这没有帮助。同时添加代码以供参考。@shahzad Visual Studio扩展似乎没有加载MahApps dll…@punker76是的,似乎是这样。但我不明白why@shahzad-你的问题已经解决了。是的,那怎么办。