StringFormat on Binding

后端 未结 9 572
野的像风
野的像风 2021-01-01 13:17

View:


I want to format the Date to \"dd/MM/yyyy\", in other words, without the time.

I

相关标签:
9条回答
  • 2021-01-01 13:41

    You can do this in xml itself. Here...

    <DatePicker 
    SelectedDate="{Binding Date, Mode=TwoWay}" 
    Text="{Binding ., StringFormat='dd/MM/yyyy'}"/>
    
    0 讨论(0)
  • 2021-01-01 13:43

    why to complicate? You can use compiled data binding

    {x:Bind ViewModel.PropertyWithDateTime.ToString("....")}
    
    0 讨论(0)
  • 2021-01-01 13:43

    There is an excellent example here:

    Example from MSDN

    if your converter class is in a different namespace (as suggested to be in a separate folder) you can add

    xmlns:conv="using:MyNamespace.Converters"
    

    and use it like this:

    <UserControl.Resources>
      <conv:DateToStringConverter x:Key="Converter1"/>
    </UserControl.Resources>
    

    the rest should stay the same as in the example from the link.

    0 讨论(0)
提交回复
热议问题