我已经创建了窗口派生类(WindowAttachedCollection.MyWindow)和持有这些窗口的集合的附加属性。但在VS 2010尝试WPF设计器创建WindowInstance对象为集合中的每个窗口,它抛出ArgumentException的:如何禁用WPF设计器中的自定义窗口呈现?
值“Microsoft.Expression.Platform.WPF.InstanceBuilders.WindowInstance”的类型是不是“WindowAttachedCollection.MyWindow”并且不能用于这个通用集合。 参数名称:值
因此,它打破了WPF设计师。
是否有任何方式如何禁用实例WindowInstance而不是WPF设计器中的MyWindow?目前,我不需要任何设计时支持MyWindow的这个集合。
编辑:
public static readonly DependencyPropertyKey DialogsPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"DialogsInternal",
typeof(ObservableCollection<MyWindow>),
typeof(MyWindow),
new PropertyMetadata(null));
public static readonly DependencyProperty DialogsProperty = DialogsPropertyKey.DependencyProperty;
public static void SetDialogs(UIElement element, ObservableCollection<MyWindow> value)
{
element.SetValue(DialogsPropertyKey, value);
}
public static ObservableCollection<MyWindow> GetDialogs(UIElement element)
{
var dialogs = (ObservableCollection<MyWindow>)element.GetValue(DialogsProperty);
if (dialogs == null)
{
dialogs = new ObservableCollection<MyWindow>();
SetDialogs(element, dialogs);
}
return dialogs;
}
感谢您的回复,但我该如何使用它?我试图给附加属性的getter和setter一些条件,但也抛出异常。理想的方式是设计师忽略这个附属性。 – Kolyk 2011-04-28 08:41:27
@Kolyk见http://stackoverflow.com/questions/826636/viewing-xaml-file-in-the-visualstudio-ui-designer-executes-the-code-behind-file – DuckMaestro 2012-05-03 22:43:53
感谢您的帮助。但它并不需要。 – Kolyk 2012-05-18 08:47:28