-1

我的解决方案中有一个 C# 类库项目,我在其中添加了一个用户控件并粘贴了我的 WPF 应用程序中的以下代码。

xaml 看起来一切都很好,但我在编译时遇到了某些错误。例如:

1) System.Windows.DataFormats' does not contain a definition for 'StringFormat'
2) System.Windows.Controls.TextBlock' does not contain a definition for 'Background' and no extension method 'Background' accepting a first argument of type 'System.Windows.Controls.TextBlock' could be found
3) System.Windows.Media.Colors' does not contain a definition for 'LightCoral'
4) System.Windows.Controls.TextBlock' does not contain a definition for 'Background' and no extension method 'Background' accepting a first argument of type 'System.Windows.Controls.TextBlock' could be found (are you missing a using directive or an assembly reference?)

我不确定为什么会出现这些错误,这些错误与 TextBox 的背景、拖放、数据格式等有关。.xaml.cs代码也在这里。http://pastebin.com/CY8E8prz

4

2 回答 2

2

您必须删除错误引用的属性,因为 Silverlight 根本没有它们,或者它们具有不同的名称(WPF 和 Silverlight 并不完全相同,前者比后者具有更多功能)。

几个例子:

  • 要为 a 的背景着色TextBlock,您可以将其包装在 a 中Border(相应地调整定位/大小属性)。
  • LightCoral看起来像一个颜色名称,你必须查找类似的东西或使用Color.FromArgb()

简而言之,从 WPF 复制粘贴到 Silverlight 的代码很少按原样工作。

于 2012-07-26T12:47:38.633 回答
1

Textblock 在 Silverlight 中没有背景,只有 WPF。我相信你的其他错误也会随之而来。对于该特定问题,请将文本块放在另一个控件上或改用标签。对于颜色,只需查找 RGB 并直接设置。我不确定其他错误是否准确。

于 2012-07-26T12:53:12.597 回答