2012-02-24 98 views
1

我使用ReSharper的6.1.1,并具有在我的项目启用solution wide analysis一个错误显示出来:避免“目标式‘类型名称’是无法转换为基地System.String类型”

Target type 'CustomControls.XSButton' is not convertible to base type System.String

的代码编译并运行良好,因为WPF中的内置TypeConverter负责处理此问题,在ReSharper bug report中对此进行了简短描述。

请注意,XSButton是在我的解决方案中的程序集中声明的 - 它不是内置类型的WPF。

这是在<Style>标记处导致此错误的xaml代码。

<CustomControls:XSButton 
     Content="i" Grid.Column="2" Command="ApplicationCommands.Help" 
     Grid.Row="0" Grid.RowSpan="2" ToolTip="Show Help" Visibility="Collapsed"> 
    <CustomControls:XSButton.Style> 
     <Style TargetType="{x:Type CustomControls:XSButton}"> 
      <Setter Property="Height" Value="26"/> 
      <Setter Property="Width" Value="26"/> 
      <Setter Property="CornerRadius" Value="13"/> 
     </Style> 
    </CustomControls:XSButton.Style> 
</CustomControls:XSButton> 

有什么办法避免这种情况:

  • 属性需要一个System.String等什么字符串字面量应该我取代类型实例与?
  • 有什么办法可以忽略这个ReSharper错误?
  • 是否以任何方式到rearange xaml避免这个错误?例如。 se属性directl而不是使用setters?

编辑

只有在风格标签同一类型的标签,在这种情况下出现的问题“富:酒吧”。请注意,我是开放式的,可以避免这种错误?也许完全重新安排xaml代码。

enter image description here

回答

3

不幸的是,在R·6.1.1的错误。问题已经解决,下一个主要R#版本将提供修复。抱歉给你带来不便。

你真的可以简单的解决办法是这样的:

<foo:Bar Command="ApplicationCommands.Help"> 
    <!-- just use the separate resource for base style: --> 
    <foo:Bar.Resources> 
    <Style x:Key="baseStyle" TargetType="{x:Type foo:Bar}"> 
    </Style> 
    </foo:Bar.Resources> 

    <foo:Bar.Style> 
     <Style TargetType="{x:Type foo:Bar}" 
       BasedOn="{StaticResource baseStyle}"> 
      <Setter Property="VerticalAlignment" Value="Top"/> 
     </Style> 
    </foo:Bar.Style> 
</foo:Bar> 

只要把BasedOn样式声明成单独的资源。

+0

我alrady使用R#版本6.1.1。查看我更新的问题 – vidstige 2012-02-27 08:03:43

+0

在此代码片段中,您使用了WPF内置类型,而我使用在我的程序集中声明的类型。 – vidstige 2012-02-27 08:05:46

+0

@ContolFlow嗨,我添加了一些更多的信息。似乎它有可能避免这一些如何。就像不使用setters,但立即或somethig分配适当的... – vidstige 2012-02-28 09:11:27

1

若要隐藏ReSharper的解决方案广泛分析的错误,您可以设置您的错误被忽略。
打开Soultion错误窗口通过ReSharper-> Windows的> Soultion错误窗口
右键单击恼人的错误,并选择忽略错误

这里是另一个错误作为例子的屏幕截图:

如果您想再次启用错误你能恢复的错误忽略:

Stopping ignoring error

+0

谢谢。也像魅力一样工作! – vidstige 2012-02-29 15:11:15

相关问题