Function binding is possible in WPF, but it usually hurts. In this case, a more elegant approach would be to create another property that returns a formatted string and binds to it.
class FileInfo { public int FileSizeBytes {get;set;} public int FileSizeFormatted { get{
In XAML, bind to FileSizeFormatted :
<DataGridTextColumn Binding="{Binding Path=FileSizeBytes, Mode=OneWay}" Header="Size" IsReadOnly="True" />
EDIT An alternative solution, thanks to Charlie for pointing this out.
You can write your own value converter by running IValueConverter .
[ValueConversion(typeof(int), typeof(string))] public class IntConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
Then in XAML:
<UserControl.Resources> <src:DateConverter x:Key="intConverter"/> </UserControl.Resources> ... <DataGridTextColumn Binding="{Binding Path=FileSizeBytes, Mode=OneWay, Converter={StaticResource intConverter}}" Header="Size" IsReadOnly="True" />
Igor Zevaka
source share