WPF运行错误:Ambiguous type reference. A type named 'VisualState' occurs in at least two namespaces
This error(most of the time warning) will occur when using two or more references which contains same namespace and classes. in your case you are using VisualState which is part of PresentationFramework assembly and you might have added another assembly which contains same "VisualState" object with the same namespace "System.Windows" .
该错误产生的原因是,两个或两个以上的引用包含相同的命名空间和类,我的程序中使用的VisualState是PresentationFramework数据源的一部分,同时程序中又添加了另外一个数据源,该数据源同样包含了命名空间System.Windows和VisualState对象。
修改办法:引入PresentationFramework命名空间
xmlns:vsm ="clr-namespace:System.Windows;assembly=PresentationFramework"
有错误的代码:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
将以上代码替换成:
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="MouseOver"/>
错误立刻消失不见了,呵呵!