我有一个小窗口,当我尝试加载应用程序启动时。这里是(松散的)XAML:尝试使用标记扩展时出错
<ctrl:MainWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctrl="clr-namespace:Controls;assembly=Controls">
<Grid>
<ctrl:ConnectionStatusIndicator/>
<TextBlock Grid.Row="2" Text="{Resx ResxName=MyApp.MainDialog, Key=MyLabel}"/>
</Grid>
</ctrl:MainWindow>
请注意称为ConnectionStatusIndicator的自定义控件。它的代码是:
using System.Windows;
using System.Windows.Controls;
namespace Controls
{
public class ConnectionStatusIndicator : Control
{
public ConnectionStatusIndicator()
{
}
static ConnectionStatusIndicator()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ConnectionStatusIndicator),
new FrameworkPropertyMetadata(typeof(ConnectionStatusIndicator)));
IsConnectedProperty = DependencyProperty.Register("IsConnected", typeof(bool), typeof(ConnectionStatusIndicator), new FrameworkPropertyMetadata(false));
}
public bool IsConnected
{
set { SetValue(IsConnectedProperty, value); }
get { return (bool)GetValue(IsConnectedProperty); }
}
private static DependencyProperty IsConnectedProperty;
}
}
现在,这里是它变得奇怪(对我来说,至少)。使用上面显示的XAML,我的应用程序将构建并运行得很好。但是,如果我删除以下行:
<ctrl:ConnectionStatusIndicator/>
或事件将其移动一行下来,我得到以下错误:
Additional information: 'Cannot create unknown type '{ http://schemas.microsoft.com/winfx/2006/xaml/presentation }Resx'.' Line number '13' and line position '33'.
什么是真奇怪,我是说,如果我更换ConnectionStatusIndicator与来自同一个程序集的另一个自定义控件一起,我得到错误。另一个自定义控件非常相似,但有更多的属性。
任何人都可以解释这里发生了什么?
不应该命名空间为:CNC.UI.Controls在XAML? – CSharpie
这是什么?{ResxName = MyApp.MainDialog,Key = MyLabel}? –
之前我曾经被咬过的一件事是,如果依赖项属性不公开,设计师喜欢采取行动。尝试将“IsConnectedProperty”公开标记,看看它是否有帮助。 – Psytronic