Hello
I have a XamDataCards object that takes a custom Person object as its DataSource.
Person object has a number of public fields. One of them is FullAddress which is of type string and the value contains new line delimiters "\r\n".
Can I somehow format the field value cell of the DataCard to display the FullAddress text in multiple lines?
For example, if the value is
"Home House \r\n 31 Low Street \r\n London \r\n SW5 7NL"
to display it as
"Home House
31 Low Street
London
SW5 7NL"
in the cell.
Many thanks.
Kostas.
Hello Kostas,
By default the CellValuePresenter will display the text on multiple lines. The issue is that the size of the CellValuePresenter for the field is not large enough to display all of the text. The easiest way to resolve this is to set the Height for the field:
<igDP:XamDataCards.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="ID"/>
<igDP:Field Name="Name"/>
<igDP:Field Name="FullAddress" Height="50"/>
</igDP:FieldLayout>
</igDP:XamDataCards.FieldLayouts>
In theory you could also bind the Height property to the value of the field and use a converter to determine how large it should be based off of the amount of new line characters are in the text along with the font size of the text. This could prevent the fields being too large though all cards would have the same height for the FullAddress field.
Hi Jason ,
Changing Height of the field as per the number of newline characters in the field text would be much difficult because we have to write converter and calculate number of new lines and multiply that count with minimum height.
Here i'm proposing a solution which doesn't require any converter. simply change the Control Template of the CellValuePresenter:
<Style x:Uid="Style_1" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<TextBlock Height="Auto" Text="{TemplateBinding Content}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Regards
Sanath
I am running into the same problem.
For me, the text that is displayed can be of varying length (not sure how many line breaks will be in it), and thus I can't seem to find a good default height as in your first suggestion. (It can range from 1->10 line breaks).
My dataCards run in two modes; one where everything is on one line; and one where they become expanded. When switching between the modes in a XamDataGrid, the rows grow to fit the required height of the additional text in the textblock; however the cells in the XamDataCards remain the exact same height.
I am interested in your suggestion:
"In theory you could also bind the Height property to the value of the field and use a converter to determine how large it should be based off of the amount of new line characters are in the text along with the font size of the text."
But am having no luck implementing this. I am not sure how to retrieve the field 'Value' when binding to the Height property of the <Field> property of the XamDataCards. If you could help point me in the right direction for how to do this, I will be happy to share my findings going forward.
Another caveat to all of this is that in the fields that I would like to bind height settings for, their CellValuePresenterStyle is set to a custom style (which, in my case contains a button and a TextBlock in a Grid).
Many thanks Jason!