惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
S
Secure Thoughts
L
LINUX DO - 最新话题
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Announcements
Recent Announcements
S
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyberwarzone
Cyberwarzone
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Vulnerabilities – Threatpost
T
Tor Project blog
GbyAI
GbyAI
B
Blog
博客园 - 司徒正美
博客园 - 叶小钗
Recorded Future
Recorded Future
F
Fortinet All Blogs
Spread Privacy
Spread Privacy
IT之家
IT之家
Forbes - Security
Forbes - Security
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
博客园 - 聂微东
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
O
OpenAI News
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 大熊(BigBear)

ADO.net实现批量SQL操作. - 大熊(BigBear) - 博客园 Application_AcquireRequestState事件,导致Ajax客户端不能加载 CSLA.Net在Web项目中使用SQL2005的分页 Moss中Form验证中"找不到匹配项"问题的处理 对于知识库系统建设的思考 知识管理中知识地图详解〔转〕 知识管理中的一些概念 Aop面向方面编程之PostSharp框架 [摘]IIS上部署WCF的问题 Linq使用之分组 页面加载性能的优化 由一棵树绑定引发的遐想 IBatis.Net使用MemCached替换内置缓存策略 .Net下调用Java安全Web服务 Webpart深入(二) Webpart深入(一) ASP.NET MVC 中文文档3 ASP.NET MVC 中文文档2 ASP.net MVC 中文文档1
Silverlight表格绑定中的一点细节处理
大熊(BigBear) · 2009-11-25 · via 博客园 - 大熊(BigBear)

1. 如何设置单元格的对齐方式

    <UserControl.Resources>
        <Style x:Key="AlignCenter" TargetType="data:DataGridCell">
            <Setter Property="HorizontalContentAlignment" Value="Right" />
        </Style>
    </UserControl.Resources>

首先设置如上样式, 然后在Grid列中指定如下属性:

<data:DataGridTextColumn CellStyle="{StaticResource AlignCenter}"/>

2. 如何绑定时格式化. 比如取成百分比, 截断字符等.

先声明一个转换类.实现IValueConverter接口.

public class ToPercentConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double valueDouble;
            if (double.TryParse(value.ToString(), out valueDouble))
                return Math.Round(valueDouble, 2).ToString("#0.00") + "%";
            else
                return "0.00%";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return double.Parse(value.ToString().Replace("%", ""));
        }

        #endregion
    }

另外发现个问题, Ojbect value 传入值是0的时候, (double)value, 居然回抛异常, 强制转换失败, 何解? 知道请回复一句,谢谢.

所以写成了TryParse的方式.

之后在使用时, 先在Xaml中声明类.

   <UserControl.Resources>
        <Bingosoft_CommonLib_SL:ToPercentConverter x:Key="ToPercentConverter"/>
    </UserControl.Resources>

在DataGrid绑定时:

<data:DataGridTextColumn  Binding="{Binding theRate, Converter={StaticResource ToPercentConverter}}"/>

就实现自定义格式化了, 以前Asp.net中一个Eval("data","formate")就搞定的, 如今这么麻烦, 有更简单的方法忘告知.