如果設置爲數據上下文的視圖模型在靜態類中註冊自己,則XAML設計器會使Visual Studio 2010崩潰。XAML設計器崩潰,自注冊ViewModel
查看
<Window x:Class="CTL.Editor.View.EditorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:editor="clr-namespace:CTL.Editor.ViewModel.Editor"
Height="300" Width="300">
<Window.DataContext>
<editor:EditorWindowViewModel />
</Window.DataContext>
<Grid>
</Grid>
</Window>
視圖模型:
public EditorWindowViewModel()
{
ApplicationViewModel.EditorWindows.Add(this);
}
~EditorWindowViewModel()
{
ApplicationViewModel.EditorWindows.Remove(this);
}
有沒有解決這個辦法嗎?也許是#指令?
謝謝,這正是我正在尋找的。我計劃在訴諸代碼之前再調查一下代碼,但至少有一些選擇。 – 2014-09-03 12:45:45
該問題似乎是由靜態類中的列表中的.Add()調用引起的(列表正在初始化)。 – 2014-09-04 22:52:06