首页 > 解决方案 > 从 ViewModel 类动态返回颜色

问题描述

我是 Xamarin 表单应用程序开发的新手,我正在尝试从我的 ViewModel 类中返回“颜色”,但我也面临同样的问题。它在 Android 设备上运行时运行良好,但在 iOS 上运行时出现以下错误:

The name 'Color' does not exist in the current context

The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)

我尝试在 iOS 项目中添加 System.Drawing dll,但错误仍然存​​在,我还使用 NuGet 更新了所有组件。

我的代码片段:

public class Ticket: BaseViewModel
{
    // Property to return

public Color PriorityColor
{
    get
    {
        if( condition ) {
            return Color.Red;
        } else if( condition ) {
            return Color.Black;
        } else {
            return Color.Yellow;
        }
    }
}
}

标签: xamarinxamarin.formsxamarin.ios

解决方案


推荐阅读