我已經創建了窗口派生類(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