【发布时间】:2014-07-16 22:24:48
【问题描述】:
我正在尝试在我的用户控件 dll 中使用 WPFToolkit。我在其引用中插入了 WPFToolkit,并且我的用户控件 dll 构建没有错误。 然后我将我的用户控件 dll 插入到我的应用程序中,但是当我的应用程序新建我的用户控件 dll 的对象时
MultiROIStats mroi = new MultiROIStats();
发生了异常,说:
其他信息:无法加载文件或程序集“WPFToolkit,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。系统找不到指定的文件。
这是我的用户控件dll代码,发生错误的构造函数。
查看xaml代码:
<Window x:Class="MultiROIStats.MultiROIStats"
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:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<dg:DataGrid ItemsSource="{Binding Path=FileData}" Margin="0,30,0,0" />
<Button Height="22" HorizontalAlignment="Left" Margin="8,4,0,0"
Name="button1" VerticalAlignment="Top" Width="48"
Command="{Binding Path=GetDataCommand}">Button
</Button>
</Grid>
</Window>
查看 C# 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MultiROIStats
{
using System.Windows;
using ViewModel;
//xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class MultiROIStats : Window
{
public MultiROIStats()
{
InitializeComponent(); // exception occurs here!
DataContext = new MultiROIStatsViewModel();
}
}
}
我还检查了我的用户控件 dll 的二进制文件夹,WPFToolkei.dll 在那里。所以我很困惑,我想知道如何纠正这个错误?谢谢。
【问题讨论】:
-
我认为问题是由于您在用户控件的构造函数中设置了 DataContext 。暂时请注释掉该行。你可能没有遇到这个问题。如果你仍然有这个问题,那么可能还有其他原因。
-
@AshokRathod 谢谢。我已经尝试删除 DataContext 行,但问题仍然存在。
-
@Ono 你能解决吗?
标签: c# wpf dll constructor wpftoolkit