簡體   English   中英

將代碼移植到Silverlight時出錯

[英]Errors while porting code to 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 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的背景,拖放,DataFormats等有關。.xaml.cs代碼也位於此處。 http://pastebin.com/CY8E8prz

您必須刪除錯誤所引用的屬性,因為Silverlight根本沒有它們或它們具有不同的名稱(WPF和Silverlight並不完全相同,前者比后者具有更多功能)。

一些例子:

  • 要為TextBlock的背景着色,您可以將其包裝在Border (相應地調整定位/大小屬性)。
  • LightCoral看起來像一個顏色名稱,您必須查找類似的內容或使用Color.FromArgb()

簡而言之,從WPF復制粘貼到Silverlight的代碼很少能保持原樣。

Textblock在Silverlight中沒有背景,只有WPF。 我相信您其余的錯誤也會照做。 對於該特定問題,請將文本塊放置在另一個控件上或使用標簽代替。 對於顏色,只需查找RGB並直接設置即可。 我不確定其他錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM