I have a Label:
<Label Name="lblBilledDate"
Content="{Binding Path=BilledDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
</Label>
It is bound to a DateTime
value.
How can i change the label to display the value to this: DisplayFormatString="dd MMM yyyy"
Currently the Label just dispalys: 1/1/2010
I need it to dispaly: 1 Jan 2010
%s specifically is used to perform concatenation of strings together. It allows us to format a value inside a string.
In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Parameter: The locale value to be applied on the format() method.
A date and time format string is a string of text used to interpret data values containing date and time information. Each format string consists of a combination of formats from an available format type. Some examples of format types are day of week, month, hour, and second.
Use the ContentStringFormat
attribute.
<Label x:Name="SomeLabel"
Content="{Binding BilledDate}"
ContentStringFormat="dd MMM yyyy" />
This is because Label
inherits from ContentControl
. Any ContentControl
contains the ContentStringFormat
attribute. Additionally, ItemsControl
has ItemStringFormat
and BindingBase
has StringFormat
.
What about this one?
<Label name="lblSomeLabel">
<Binding Path="Date" StringFormat="{}{0:dd MMM yyyyy}"/>
</Label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With