C# 在资源字典的同一程序集中引用WPF控件类
我有一个扩展System.Windows.Controls.Control的类,我打算将其转换为自定义控件,以便在WPF应用程序中使用,如下所示:C# 在资源字典的同一程序集中引用WPF控件类,c#,wpf,xaml,controls,xml-namespaces,C#,Wpf,Xaml,Controls,Xml Namespaces,我有一个扩展System.Windows.Controls.Control的类,我打算将其转换为自定义控件,以便在WPF应用程序中使用,如下所示: namespace MyNamespace { public class CustomControl : Control { // Implementation } } 所有Windows和代码文件都使用MyNamespace命名空间,无论它是xaml文件还是.cs文件。因此,在同一命名空间(MyNamesp
namespace MyNamespace
{
public class CustomControl : Control
{
// Implementation
}
}
所有Windows和代码文件都使用MyNamespace命名空间,无论它是xaml文件还是.cs文件。因此,在同一命名空间(MyNamespace)中引用此类应该很容易,如下所示:
如何让Mynamespace.CustomControl在xaml中工作?在我编译项目之前,我曾在Visual Studio Community 2015中按F7进行编译,这对我来说很有效。第一个自定义控件显示了该错误。是编译时的错误还是设计时的曲线扭曲?这是设计时的扭曲错误。它运行正常,但如果可能的话,我想解决问题的根源,所以我不想知道当我遇到bug时会发生什么。
<Window x:Class="MyNamespace.CustomWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlsn:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace"
Title="MyCustomWindow">
<Grid>
<local:CustomControl />
</Grid>
</Window>
<Window x:Class="MyNamespace.CustomWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlsn:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNamespace"
xmlns:otherAssembly="clr-namespace:OtherNamespace;assembly=OtherAssembly"
Title="MyCustomWindow">
<Grid>
<otherAssembly:OtherCustomControl />
</Grid>
</Window>