advanced datagrid column binding (for a datetime)
-
I'm using an unconventional object oriented database which uses a long to store datetimes. This is directly convertible to a DateTime, but how could i display it as a DateTime using column binding? Because of the object oriented database i can't add an accessor to the class that returns the long casted to a DateTime (ex. DateTime.FromFileTime(timeStamp) ), becuase the db does not know how to correctly handle it. Is there something I could do with string.format? Or something i could do if i had a different column type (instead of Microsoft.Windows.Controls.DataGridTextColumn)? Seems far-fetched, but how about a column that can bind to a method's return value? I'm trying to avoid having to inherit from the type used in the DB but as a last resort I could do that.
-
I'm using an unconventional object oriented database which uses a long to store datetimes. This is directly convertible to a DateTime, but how could i display it as a DateTime using column binding? Because of the object oriented database i can't add an accessor to the class that returns the long casted to a DateTime (ex. DateTime.FromFileTime(timeStamp) ), becuase the db does not know how to correctly handle it. Is there something I could do with string.format? Or something i could do if i had a different column type (instead of Microsoft.Windows.Controls.DataGridTextColumn)? Seems far-fetched, but how about a column that can bind to a method's return value? I'm trying to avoid having to inherit from the type used in the DB but as a last resort I could do that.
You can either use an IValueConverter or StringFormat in your binding. You could also wrap your object in another object that exposes a property that does custom string formatting, but that would be a lot of extra work you don't need if you use the above techniques I mentioned.
-
You can either use an IValueConverter or StringFormat in your binding. You could also wrap your object in another object that exposes a property that does custom string formatting, but that would be a lot of extra work you don't need if you use the above techniques I mentioned.
-
Thanks. That IValueConverter is fun and I'll use it, but i was wondering what the code would look like to use stringformat. I can't quite figure it out.
Hmmm, you'd probably have to do some math to get it to display in the proper format... not sure you can do that with StringFormat, now that I think about it. I'd stick with IValueConverter.