我正在使用 WPF 互操作性 (ElementHost) 在 WinForms 中显示 XAML 控件。这非常适合我的需求,因为我必须使用 WinForms 来处理我正在从事的项目。问题是,当我将图像(例如图标)添加到 XAML 中的功能区时,我无法再将 XAML 功能区添加到 WinForm。我不断收到的错误是:
An error occurred trying to create an object of type 'WPF.Ribbon'. Make sure the type has a default constructor.
图像的构建操作为“资源”。以下是我用于功能区代码的示例 XAML 代码片段:
<RibbonButton SmallImageSource="/App/Images/Ribbon/cut.png" Label="Cut" KeyTip="X" />
当我删除图像源时,我可以很好地编译代码,并且功能区显示没有任何问题。
最佳答案
解决方法是添加绝对地址,如:
<RibbonButton SmallImageSource = "C:\Path To Images\App\Images\Ribbon\cut.png" Label="Cut" KeyTip="X" />
关于wpf - 元素主机 : Images in XAML Ribbon Causing Issues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27750472/