我在Visual扩展中的工具箱的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>
但无论发生什么,我都会收到以下错误。
System.Windows.Markup.XamlParseException类型的第一次例外发生在PresentationFramework.dll中 其他信息:无法加载文件或程序集“MahApps.Metro,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件。
我已经尝试过安装/卸载、删除/添加引用,但到目前为止没有任何工作。
发布于 2016-10-13 07:16:02
这是因为在编译Visual扩展时,没有将MahApps.Metro作为引用包括在内。
我不完全确定为什么,但是如果您只在XAML中使用MahApps,那么编译后的程序集中不包含引用。您可以通过解压缩扩展名(它只是一个zip文件)并在ILSpy中打开程序集来检查这一点。在参考资料中,不会列出MahApps。
解决这个问题的方法是在代码中的某个地方使用MahApps。最简单的方法是给您正在使用的MahApps控件命名。这将为控件生成一个字段,这似乎足以使引用包含在程序集中。
<Grid Margin="15">
<custom:Tile x:Name="MyTile" />
</Grid>
您还可以在代码中的任何其他地方使用来自MahApps程序集的对象(例如,您可以在Package
的构造函数中创建一个新对象),但是给其中一个控件命名可能是最简单的方法。
https://stackoverflow.com/questions/34024111
复制相似问题