I am trying to display Product prices in a string format in Xamarin Forms:
Text="{Binding Price, StringFormat=' Price is {0:$}'}"
Output:
Price is $
what I am doing wrong and why the binded price is not displaying?
You should use the Currency Format instead.
<Label Text="{Binding Price StringFormat='Price is = {0:C}'}" />
Related
I'm a little stuck trying to display a timespan data using the StringFormat property. I'm using the following code:
<TextBlock Text="{Binding Duration, StringFormat='Time: {0:HH.mm}'}" FontSize="12" />
When I run my App to test it, after to click on a button to retrieve some data (in which a timespan value is include), the App simply gets frozen.
However, If I don't use the string format property, the data is displayed OK in the format of:
00:03:49.4590000
The above output is the one I wanna displayed either as 00:03:49 (HH:mm:ss) or 03:49 (mm:ss)
Also, I found this code which suppously do the same:
<TextBlock Text="{Binding Duration, StringFormat=\{0\:N0\}}" FontSize="12" />
But, the resut is the same. The App gets frozen
Does anyone have a good example how to use the string format property to dislplay a TimeSpan value?
Or do I miss something the the above code?
Regards!
You could bind TimeSpan like this, textblock will display like 02:23(2 hours and 23 minutes):
<TextBlock Text="{Binding time, StringFormat='{}{0:hh\\:mm}'}"/>
also you can convert your TimeSpan to DateTime, and bind it like this:
<TextBlock Text="{Binding time, StringFormat='{}{0:HH:mm}'}"/>
I want to display today's date in XAML and then return that to my view model. So this shows it in XAML
<TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=dd/MMM/yyyy}"/>
but I want to return it in ModifiedDate, so I did this
<TextBlock x:Name="ModifiedDate" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=dd/MMM/yyyy}"/>
This doesn't work. I don't want to use datepicker. I want to use Pure XAML and do not wish to go to code. Any ideas?
you have to include this name space in your xaml..if you are not able to show date..
xmlns:sys="clr-namespace:System;assembly=mscorlib"
and if you want something different update your question..
I am using the DataGrid of Silverlight toolkit. Now my requirement is to merge cell in some of the row in the datagrid.
Is there any way to do Cell merging in the Datagrid using silverlight.
If it's just displaying values from multiple columns in one column it is best to do this by using a DataGridTemplateColumn:
<sdk:DataGridTemplateColumn Header="Merged Cols">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Column1}" />
<TextBlock Text="{Binding Column2}" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
You could also do this through a converter if you want to use the DataGridTextColumn. As a Silverlight converter only supports one value you'd need to send the entire row.
The column definition of the DataGrid would contain
<sdk:DataGridTextColumn Binding={Binding Converter={StaticResource MergedCols}} />
You'd need to add the MergedCols converter to your solution and to your resource collection.
<UserControl.Resources>
<myConverters:MergedColsConverter x:Key="MergedCols" />
How do I go about styling a bound string to a TextBlock? I'd like to have some of the text bolded, but not all of it?
<TextBlock Name="lblZoneNumber" Margin="12, 20, 0, 0" TextWrapping="Wrap" Text="{Binding ZoneSummary}" />
A sample of the text would be:
"Your vehicle, test1234, is currently parked in Grand Rapids, MI at zone 100" and I'd like to bold the text like: "Your vehicle, test1234, is currently parked in Grand Rapids, MI at zone 100."
I can't really make these textblocks programmatically as the text is part of a view model/pivotitem.
You cannot do this until you start to develop for Mango, and then you would not use the TextBlock to do so, but the RichTextBox. A TextBlock can only have one styling. The RichTextBox is read only, BTW.
Here is a link to info about the RichTextBox: http://www.windowsphonegeek.com/articles/Windows-Phone-7-Mango-First-look-at-RichTextBox-control
i have an datagrid i am trying to bind an value to label which is under datatemplate
but no binding is happening her. ?
<sdk:Label DataContext="{Binding CompanyName}" Width="50" />
i have an column which is above datatemplate there the values are getting binded.
<sdk:DataGridTextColumn Header="CompanyName" Binding="{Binding CompanyName}"/>
but in controls inside data tempalate values are not getting binded.
image field is getting binded with image source what we have specfied.
what is the issue happening here no data binding taking place . help me out
thanks in advance
prince
the issue was the the option what i was using for binding
for label to bind we have to use this property.
Content="{Binding
CompanyName}"