Hi,Could you please provide the solution for below issue:
My Purpose :I have one "Double" field bounded to WPF XamDataGrid,and I Need to show the Parenthesis for negative values
Example -123,005 to be shown as (123,005)
My Approach:I have applied ControlTemplate and Converter to achieve my purpose
Issue : I was NOT able to EDIT this double field after applying the "Control Template" and "Converter"
Thanks,
Hello,
What you can do is to set the ValueToDisplayTextConverter property to a IValueConverter object and use it to wrap the displayed text in paranthesis.
Let me know if you have questions on this.
Hi Alex,
Could you please find refer my sample code and tell where i need to apply XamTextEditor.ValueToDisplayTextConverter ?
XAML
<Grid Name="gridPanel"> <Grid.Resources>
<Style x:Key="DoNotUseCommaUseParenthesisStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content,Converter={StaticResource parenthesisForNegativeAndNoCommaConvert}}"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
</Grid.Resources>
Code behind:
stdGrid.FieldLayouts[0].Fields["MyBalanceDoubleField"].Settings.CellValuePresenterStyle = (Style)gridPanel.Resources[DoNotUseCommaUseParenthesisStyle];
Converter Class
public class ParenthesisForMinusAndNoCommaConverter:IValueConverter { #region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double doubleValue=(double)value; if (doubleValue < 0) { string absoluteStrVal = Math.Abs(doubleValue).ToString(); return string.Format("({0})", absoluteStrVal); } return doubleValue; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); }
#endregion }
Rebinding the XamDataGrid will reinitialize the records. Also scrolling them out and back in of view, grouping, ungrouping, expanding collapsing are all actions that will make the record to initialize.
Could you please tell the way to raise the InitializeRecords() Event?
Then you should create if you have not created or get the style (if you have already defined it in the resources somewhere) and apply it to this field. However, I believe you would have to reinitialize the records in order for this change to take effect.
Hi Alex Fidanov,Thanks a lot for the suggestion.
Could you please provide solution for the below issue:
NOW : I can able to use this Converter on code behind file on XamGrid_Loaded() event. It's working fine.
My Issue / Need : I need to apply this dynamically on clicking "Menu" on Menu bar
Thanks.
For this, you do not have to retemplate the cellvaluepresenter. What you need to do is the EditorStyle property of the Field's Settings, like this:
<igDP:Field Name="ClientName">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamTextEditor}">
<Setter Property="ValueToDisplayTextConverter" Value="{StaticResource conv}"/>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>