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

推荐订阅源

V
Visual Studio Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
V
V2EX
博客园_首页
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
H
Help Net Security
A
About on SuperTechFans
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
云风的 BLOG
云风的 BLOG
D
Docker
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
T
Troy Hunt's Blog
T
Tenable Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Recorded Future
Recorded Future
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog
T
Threat Research - Cisco Blogs
MyScale Blog
MyScale Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence

博客园 - 大熊(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")就搞定的, 如今这么麻烦, 有更简单的方法忘告知.