我可以成功添加在我的主項目的Assets程序集中定義的控件。WPF:無法將Name或EventHandlers添加到在不同程序集中定義的自定義控件的實例中
例如,像這樣的控制:
using System.Windows.Controls;
namespace AdvancedAudioGui.Assets.Controls
{
public class MyControl: Control
{
public string MyProperty { get; set; }
}
}
是這樣工作的:
<UserControl x:Class="MyCompanyName.AdvancedAudioGui.Parts.MyPart"
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:controls="clr-namespace:AdvancedAudioGui.Assets.Controls;assembly=AdvancedAudioGui.Assets"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<controls:MyControl />
</Grid>
,但不喜歡這樣的(注:同樣的事情發生的名稱或事件處理程序像MouseDown):
<UserControl x:Class="MyCompanyName.AdvancedAudioGui.Parts.MyPart"
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:controls="clr-namespace:AdvancedAudioGui.Assets.Controls;assembly=AdvancedAudioGui.Assets"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<controls:MyControl x:Name="MyInstance"/>
</Grid>
我得到的錯誤:
類型或命名空間名稱「資產」的命名空間中不存在「OurCompanyName.AdvancedAudioGui」(是否缺少程序集引用?)
如果我創建他們在代碼後面我可以添加一個名稱,所以它必須是一個xmlns問題,但我看不到它。有任何想法嗎?
謝謝!
如果我用2個項目和一個控件創建一個新的基本解決方案,我沒有這個問題。我無法找到我在我的真實解決方案中所做的導致此問題的原因。 –