I have a XamDataGrid with columns that contain a different set of numbers depending on the row they are located in. For example, the first row contains the amount of money available for you. The second row contains the closing price of a stock from yesterday. The third row contains the live price and the change in price from yesterday. So it looks something like:
| Available | 1,000 |
| Previous | 88.00 |
| Live | 65.25 (-22.75) |
Is it possible to line up the data based on the decimal points? For example, the 88.00 would be directly over the 22.75 in the Live row and the last 2 00s from the Available row would be over the 22 and 88 respectively. I'm sure there has to be some style or converter out there but I can't seem to generate it.
Your description is a little hard to follow, but I'll take a stab at a possible answer.
From what you pasted it looks like your record orientation is set to horizontal, and you'd like to align the cell values. One possible way would be to create a style that right aligns the values like below.
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="RightAlignedValueStyle">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Padding" Value="0,0,5,0" />
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="Available">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource RightAlignedValueStyle}" />
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="Previous">
<igDP:Field Name="Live">
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
No they are all vertical. I've attached a quick sample of the issue that I'm having.
Hi,
I reviewed your sample and I believe that the RightAlignedValueStyle didn’t resolve your original questions on how to line up the decimal points of the items although it does right align the values in the fields.
What I do also see is that the Properties items are string values. If they are indeed strings that you need to work with you could manipulate the values to contain the appropriate spaces to the right to force the decimal to line up.
Or you could use a converter to convert the string based on the value content.
I suspect that you will want to use a converter and then use some string functions to identify the type of values (do they contain commas or decimal points or more than one decimal point) you are working on.
Based on that information you will need to add the appropriate space to the string and return the value.
You may also need to modify the ConvertBack as well in order to return the original value without the modifications.
Let me know if you have questions about creating a converter.
I hadn't heard back from you and I'm wondering if you had any further questions
Can you provide example/sample code for the converter which can be applied to the particular column of the xamdatagrid.
Regards,
Sohail Kazmi.
Hi Sohail,
I didn't see your question. I don’t know if you are returning the DataRecord or the Cell value to your converter or multiple cell values.
Let me pass this to you. It’s for an unbound field using multivalueconverter but the binding and the converter should be helpful to you. And there is a description of other binding you might consider.
<igDP:UnboundField Name="unboundCheckBox" >
<igDP:UnboundField.Settings>
<igDP:FieldSettings EditAsType="{x:Type sys:Boolean}">
<igDP:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type igDP:CellValuePresenter}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<CheckBox x:Name="unbCB">
<CheckBox.IsEnabled >
<MultiBinding Converter="{StaticResource IsEnabledConverter}">
<MultiBinding.Bindings>
<Binding />
<Binding RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
<Binding Path="Cells[2].Value"/>
<Binding Path="Cells[3].Value"/>
</MultiBinding.Bindings>
</MultiBinding>
</CheckBox.IsEnabled>
<!--
<Binding Path="Cells[0].Value"/>
<Binding Path="Cells[1].Value"/>
<Binding Path="DataRecord"/>
<Binding Path="DataItem"/>
returns Context
returns DataRecord
returns specific cell values convert to string
return unset value
return null (there is no DataItem of Context)
-->
</CheckBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</igDP:FieldSettings.CellValuePresenterStyle>
</igDP:FieldSettings>
</igDP:UnboundField.Settings>
</igDP:UnboundField>
public class checkBoxTagConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue)
return Binding.DoNothing;
}
Field fld = values[0] as Field;
DataRecord rcd = values[1] as DataRecord;
if (null == fld || null == rcd)
return rcd.Cells[fld];