20

安装 Visual Studio 2012 并打开 Silverlight 5 项目后,我遇到了与 TypeConverter 相关的各种设计时错误,例如:

“FontWeight”的 TypeConverter 不支持从字符串转换。

“Point”的 TypeConverter 不支持从字符串转换。

“Thickness”的 TypeConverter 不支持从字符串转换。

然而,这并不是一份详尽的清单。

这些例子是:

<Setter Property="FontWeight" Value="Bold" />

<RadialGradientBrush GradientOrigin="0.5,0.5"> ...

<Setter Property="Padding" Value="0" />

我在这里遗漏了一些明显的东西,还是这是一个错误?

4

3 回答 3

17

我有同样的问题:在资源部分定义

<UserControl.Resources>
  <local:MyConverter x:Key="myConverter"/>
</UserControl.Resources>

在 XAML UE 中,我不得不改变

...Width="{Binding BindingProperty, Converter=myConverter}"...

...Width="{Binding BindingProperty, Converter={StaticResource myConverter}..."
于 2012-11-19T06:31:20.120 回答
1

有一个类似的问题:

The TypeConverter for "Thickness" does not support converting from a string

此 XAML 文件中未使用任何转换器

这是一个已从 SL4 转换为 SL5 的 Silverlight 项目(Prism)。但似乎还有更多的事情发生,我也收到这样的错误:

The specified value cannot be assigned to the collection. The following type was expected: "Inline".

当 TextBlock 像这样使用时:

<TextBlock>Hello</TextBlock>

要摆脱该错误:

<TextBlock Text="Hello" />

启动应用程序查看XAML更改的结果有点麻烦

于 2012-11-29T13:21:57.723 回答
1

我有同样的问题,它让我发疯!对我来说,这与 Silverlight 工具包有关,一旦我补充说我开始收到大量这些错误。

在我的项目文件(右键单击->编辑项目文件)中,我已经像这样引用了工具包 dll(在我的情况下,相对于源目录):

<Reference Include="System.Windows.Controls.Toolkit">
    <HintPath>..\..\..\Bin\System.Windows.Controls.Toolkit.dll</HintPath>
</Reference>

将其更改为此似乎可以对其进行排序(我不确定是否也需要内部组件,但添加了 SL5 和工具包的新项目似乎可以引用它):

<Reference Include="system.windows.controls.toolkit, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Windows.Controls.Toolkit.Internals, Version=4.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

希望有帮助,约翰

于 2013-09-17T10:21:43.237 回答