我正在尝试使用silverlight-5开发c#web应用程序。
我必须创建一个进度条,它将有两种颜色为绿色(高达某个百分比),然后是红色,这将通过c#中的某些数据操作动态完成。
我希望通过一定比例的绿色和休息红色来制作两种颜色(百分比将在运行时决定)。我阅读了几份文件但很难理解。
有人可以帮我写一下c#中的代码吗? (或者,如果此进度条不会按运行时获取的值更改颜色,那么请编写一个简单的代码来创建自定义进度条,根据运行时更改的值在运行时更改颜色)。会是一个很大的帮助。谢谢
可能我想代码将用c#编写,因为在xaml中颜色显示比例将是固定的,但这两种颜色的百分比必须根据c#中运行时获得的数据值而改变代码
注意:我正在使用silverlight和c#开发webapplication。
所以代码必须像这样写在正文中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace B
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
}
编辑:我试图做
progressBar.ForeColor = Color.FromArgb(255,0,0);
它给了我错误"使用System.Drawing.Color;"错误是:类型或命名空间名称'绘图'命名空间中不存在'系统' (你错过了一个装配参考吗?
当我尝试使用System.Drawing.Color添加" "
并且没有程序集我可以找到b名称" System.Drawing.dll"
可能是Silverlight版本问题或可能是其他一些问题。
有人可以帮我动态更改进度条颜色变化吗?感谢
答案 0 :(得分:1)
在这里你需要验证你的进度条值,例如当它的值= 80%然后改变颜色并改变你需要做的颜色
progressBar.ForeColor = Color.FromArgb(255, 0, 0);
您可以将颜色更改为任何颜色。