如何在我的WPF项目中加载(XAML)我的UserControl? [英] How do I load (XAML) my UserControl in my WPF project?
问题描述
当我尝试在我的WPF项目中加载现有的工作UserControl时,我总是收到以下错误消息:
无法加载元数据汇编'LowLightGrab'。该程序集可能已从Web下载。请参阅http://go.microsoft.com/fwlink/?LinkId=179545。加载期间遇到以下错误:无法加载文件或程序集LowLightGrab,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null或其依赖项之一。尝试加载格式不正确的程序。 c:\ temp \WpfApplication1LL_Neu \WpfApplication1LL_Neu \ MainWindow.xaml
此UserControl'LowLightGrab'作为WPF位于本地路径中项目。
我的XAML代码是:
When I try to load an existing and working UserControl in my WPF-project I allways get following error message:
Unable to load the metadata for assembly 'LowLightGrab'. This assembly may have been downloaded from the web. See http://go.microsoft.com/fwlink/?LinkId=179545. The following error was encountered during load: Could not load file or assembly 'LowLightGrab, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. c:\temp\WpfApplication1LL_Neu\WpfApplication1LL_Neu\MainWindow.xaml
This UserControl 'LowLightGrab' is in a local path as the WPF-project.
My XAML-code is:
<Window x:Class="WpfApplication1LL_Neu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lowLightGrab="clr-namespace:LowLightGrab;assembly=LowLightGrab"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WindowsFormsHost>
<lowLightGrab:UserControl1/>
</WindowsFormsHost>
</Grid>
</Window>
什么这里出错了?
谢谢!
What goes wrong here?
Thanks!
推荐答案
你为什么选择唱WindowsFormsHost加载WPF用户控件?
看起来你正试图这样做链接 [ ^ ]
如果您尝试加载WPF UserControl no需要使用WindowsFormHost。
why are you using WindowsFormsHost to load WPF usercontrol?
Looks like you are trying to do as like example available in this link[^]
If you trying to load WPF UserControl no need to use WindowsFormHost.
<Window x:Class="WpfApplication1LL_Neu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lowLightGrab="clr-namespace:LowLightGrab;assembly=LowLightGrab"
Title="MainWindow" Height="350" Width="525">
<Grid>
<lowLightGrab:UserControl1/>
</Grid>
</Window>
以上代码就够了如果lowlightgrab:usercontrol1是WPF UserControl
the above code is enough If the lowlightgrab:usercontrol1 is a WPF UserControl
这篇关于如何在我的WPF项目中加载(XAML)我的UserControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!