Very good way of formatting data. To implement the interface System.Windows.Data.IValueConverter
2010-06-03 21:40
471 查看
Here is a very good way of formatting data in Silverlight.
1. Firstly, you need to implement the interface System.Windows.Data.IValueConverter. The example is to show how to convert a number to percentage.
2. After creating this class, you need to add a instance to application resources.
3. now you can use it when binding to the data.
COOL!!! Is it?
1. Firstly, you need to implement the interface System.Windows.Data.IValueConverter. The example is to show how to convert a number to percentage.
namespace FinancePCFlowTool.cs { public class PercentConverter : System.Windows.Data.IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) value = 0; return string.Format("{0:N0}%", (double)value * 100); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return 0; else return double.Parse(value.ToString().Trim('%')); } } }
2. After creating this class, you need to add a instance to application resources.
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="FinancePCFlowTool.App" xmlns:cs="clr-namespace:FinancePCFlowTool.cs" > <Application.Resources> <cs:PercentConverter x:Key="PercentConverter" /> </Application.Resources> </Application>
3. now you can use it when binding to the data.
<sdk:DataGridTextColumn Header="Consumer %" IsReadOnly="True" CanUserSort="False" CanUserReorder="False" Binding="{Binding ConumserPercent,Mode=OneWay, Converter={StaticResource PercentConverter}}" />
COOL!!! Is it?
相关文章推荐
- System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException: Operation is not valid due to the current state of the obj
- System.Security.Cryptography.CryptographicException: The data to be decrypted exceeds the maximum for this modulus of 128 bytes. (RSACryptoServiceProv
- EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
- Windows 10 is going to be the last major revision of the operating system.
- Loadrunner 11在win7录制中失败“the recording of the application was terminated by windows due to window data execution prevention feature"
- a very good guide to makethe Most Out of the SQL Server 2005 Performance Dashboard
- System.Data - System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the r
- What is the best way to create a good interface to an abstraction?
- Steps of configuring IDoc to exchange data between two clients of the same SAP system
- Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.
- [entity framework ] The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
- Data migration to generate the maximum value of the sequence between beta scheme and appbeta scheme
- ccah-500 第45题 You want to minimize the chance of data loss in your cluster. What should you do
- Teaching the Next Generation of Statistics Students to “Think With Data”: Special Issue on Statistic
- The Adapter of ListView: Just adapt data to view, don’t do anything else
- Cannot modify the return value of 'System...ClientRectangle' because it is not a variable
- Application windows are expected to have a root view controller at the end of application launch
- Is there any best way to reduce the size of ibdata in mysql.?
- [Nuxt] Add Arrays of Data to the Vuex Store and Display Them in Vue.js Templates
- No sources that matches the given name (at 'layout_toLeftOf' with value '@id/