我将wpf用户控件添加到winform项目。但是我编译失败。
我有错误。错误CS0266:无法将类型'object'隐式转换为'string'。
string abc = test.PropertyAccessor.GetProperty("name");
//type of test is Microsoft.Office.Interop.Outlook.Attachment
//test.PropertyAccessor.GetProperty return dynamic.
我找到了原因。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
xmlns:local =“ clr-namespace:CustomControls”是原因。如果xmlns:local =“ clr-namespace:CustomControls”被删除,我不会收到错误。
为什么?
我找不到原因,但是我还是解决了。我添加了显式转换。
string abc = (string)test.PropertyAccessor.GetProperty("name");