posts - 124,  comments - 29,  trackbacks - 0
运行效果见上图, 可以根据单元格中的值来设置颜色,100%为红色,其他为绿色。
实现方法:用列模板绑定数据源中定义的颜色数据项。
其中列模板用Border加TextBox构成,代码如下:
private static DataTemplate MakeCellTemplate(MyColumn col)
        {
            try
            {
                DataTemplate dt1 = new DataTemplate();
                StringBuilder xaml = new StringBuilder();
                xaml.Append("<DataTemplate ");
                xaml.Append("xmlns='http://schemas.microsoft.com/client/2007' ");
                xaml.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
                xaml.Append(">");
                xaml.Append("<Border ");
                xaml.Append("BorderThickness='0.5' BorderBrush='LightGray' Background='Orange'>");
                xaml.Append("<TextBox ");
                xaml.Append("IsReadOnly='True' Text='{Binding " + col.Name + "}' Foreground='Black' BorderBrush='White' BorderThickness='0' Background='{Binding " + col.colorValue + "}'");
                xaml.Append("/>");
                xaml.Append("</Border>");
                xaml.Append("</DataTemplate>");
                dt1 = (DataTemplate)XamlReader.Load(xaml.ToString());
                return dt1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                return null;
            }
        }
posted on 2010-12-07 16:17 天书 阅读(2512) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜