Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将代码移植到silverlight时出错_C#_Silverlight - Fatal编程技术网

C# 将代码移植到silverlight时出错

C# 将代码移植到silverlight时出错,c#,silverlight,C#,Silverlight,我的解决方案中有一个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

我的解决方案中有一个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代码也在这里

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

举几个例子:

  • 要给
    文本块的背景上色
    ,可以将其包装在
    边框中
    (相应地调整定位/大小属性)
  • LightCoral
    看起来像一个颜色名称,您必须查找类似的名称或使用
    color.FromArgb()

简而言之,将粘贴的代码从WPF复制到Silverlight很少像现在这样工作。

Textblock在Silverlight中没有背景,只有WPF。我相信你其余的错误也会如此。对于该特定问题,请将textblock放置在另一个控件上或使用标签。对于颜色,只需查找RGB并直接设置即可。我不确定其他错误是否正确。

我认为这是因为WPF和Silverlight是不同的框架。您需要做的不仅仅是粘贴代码。名称空间从一开始就是不同的。@jrummell:在这里的上下文中看起来没有什么不同。完整的.xaml.csdoe位于上面的链接中,其中“;;把事情弄清楚。@ChrisF:我所说的粘贴,并不是指在没有看到任何东西的情况下粘贴所有内容:-)。我不确定我在上文中所写的名称空间是否有差异link@user1240679我们没有记住每一种类型。当您提出这些问题时,我们会查看MSDN。这是一个非常有用的工具。如果您还没有熟悉,我建议您熟悉它。因此,没有
DragDrop
e.LeftButton
MouseButtonState
StringFormat
。这些都没有?不幸的是,从WPF到Silverlight有很多不同之处。您需要检查代码,并一次修复一个错误,除非存在某种“转换器”(对不起,我不知道有任何转换器)。在此过程中,MSDN和谷歌将是您最好的朋友。