locked
StringFormat or converter for binding dates?

    Question

  • Hi,

    I have a datetime that is being bound to a listbox and I only want to show the time portion of it.
    I've tried

    <TextBlockText="{BindingTimeFeedStart, StringFormat=t}"Margin="3,0,0,0"/>

    But this throws an error.

    Am I correct in thinking that StringFormat doesn't work on binding in windows apps?

    If this is the case, can someone please help me with a converter that I can use to get the output I require?

    Any help is gratefully received.

    Thanks

    Tuesday, March 31, 2015 1:17 PM

Answers

All replies

  • Hi,

    Is there some reason why you can't use code behind, maybe you should create a converter.

    You can even create StringFormatConverter where you can pass the DateTime format as ConverterParameter.

    See here's code & Date and time formatting sample

    --Simon

    Wednesday, April 01, 2015 3:18 AM
  • Thanks for the reply Simon.

    Managed to get it to work now.

    Still not quite sure why StringFormat hasnt been included like it is in full WPF. Makes things really easy.

    Wednesday, April 01, 2015 7:50 AM
  • Well, many things used to be easy with WPF, but with WinRT things changed. Get used to it.

    Wednesday, April 01, 2015 8:06 AM