Hi
I have a Xamgrid WPF control which displays one column bound to a view model. The column is bound to a double type field.
<ig:TextColumn Key="Value" IsReadOnly="False" ValueConverter="{StaticResource PercentConverter}">The percent converter has the following code
double val = (double)value; return val.ToString("P3");
All this works fine. I get the result as expected.
Now, the requirement is that this cell is editable and the users can update values. What is happening is that whenever I double click the cell to edit the cell does not show the converted value (in percentage) but the original value.For eg. if the actual value was 0.0037 after applying the converter the value will be displayed in the grid as 0.37%. What I want is when the user double clicks the cell to edit I want to display 0.37 (without the percentage).
Any help appreciated.
Thanks
Hi,
Actually, I would recommend that you eliminate the converter and just format the text in your TextColumn by using the FormatString. When it goes into edit mode you will see the actual value, unformatted.
It would look like this:
<ig:TextColumn Key="Value" FormatString="{}{0:P}" />
Please let me know if you have any questions.
This doesn't help either. The value does indeed get displayed in % for eg (0.00375) gets displayed as 0.38% but when I double click and it enters the edit mode the value gets converted into (0.00375).
Chev
Goad you got it to work for you.
Please let me know if I can be of any further assistance.
I got this working using template columns. Unbound did not work for me for some reason.
I was wondering if you had further questions.
Please let me know if I can help you.
Because you don't want to display the actual value but want to just show the number converted to the same appearance as the displayed value minus the percent sign, I used an UnboundColumn instead of the TextColumn. It has more flexibility and control in this case. And I used a value converter to handle the appearance when in edit mode and when returned from editing.
<ig:UnboundColumn Key="Salary" >
<ig:UnboundColumn.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding RowData.Salary, StringFormat={}{0:P}}"/>
</DataTemplate>
</ig:UnboundColumn.ItemTemplate>
<ig:UnboundColumn.EditorTemplate >
<DataTemplate >
<ig:XamMaskedInput Value="{Binding RowData.Salary, Mode=TwoWay, UpdateSourceTrigger=Explicit, Converter={StaticResource percentConverter}}" />
</ig:UnboundColumn.EditorTemplate>
</ig:UnboundColumn>
class PercentConverter: IValueConverter
{
// This converter handles a decimal value that is presented in display mode with a percent sign ("P3")
// and converts the value to appear in Edit Mode, not as actual value but similar to display mode without percent sign
// In order to achieve this it needs to convert the value by multiplying it by 100 and showing as number
// And then dividing by 100 when return value after edit is completed
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
double val = (double)value;
val = val * 100;
return val.ToString("N3");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
string stringValue = (string)value;
double val = double.Parse(stringValue);
val = val / 100;
return val;
Any suggestions?