我剛剛在使用VS2012,WPF 4.5和設計時數據(特別是DesignInstance屬性)時遇到了幾個小時問題。DesignInstance無法在VS2012中工作
目標:我想有設計時的數據支持(MVVM爲基礎的),無論是在VS2012和混合我的WPF的項目,我不能爲我的生活,享受MVVMLight方法工作一貫 。
所以我嘗試使用內置的設計時數據支持,使用Blend提供的標記擴展來更改爲「恰好」。
問題:請看下面的代碼:
<Window x:Class="Nova.View.AlertsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Nova.View"
xmlns:vm="clr-namespace:Nova.ViewModel"
mc:Ignorable="d"
DataContext="{Binding Alerts, Source={StaticResource Locator}}"
d:DataContext="{d:DesignInstance vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
... />
無論VS2012和Blend報告「的名字DesignAlertsViewModel沒有命名空間中的CLR命名空間存在:Nova.ViewModel」,儘管智能感知解決它只是很好,你已經檢查了一千次,名字空間和類名都是正確的。
我以前有過類似的問題,並且認爲我必須註釋掉有問題的行並編譯程序集,然後在將它添加回來時工作正常。 – AlSki
我唯一的其他建議是使用完整語法,並且包括Type =即d:DataContext =「{d:DesignInstance Type = vm:DesignAlertsViewModel,IsDesignTimeCreatable = True}」 – AlSki
謝謝,@AlSki,我_did_嘗試完整的語法,但沒有運氣。設計時數據最初出現,但最終停止工作(只是消失,沒有給出錯誤)。我已經將我的「解決方案」更新爲「解決方案」,並且會進一步深入研究。 – Thomas