Search code examples
c#wpfcoding-style

Show 4 digits after comma WPF


I have developed WPF code; I'm showing a figure like 0.77. But I want to show a figure like 0.7777. I have two separate styles for both GridColumn and TextBox.

My code for gridcolumn is:

<Style TargetType="{x:Type dxg:GridColumn}" x:Key="dxGridColumnNumber" >
    <Setter Property="ColumnHeaderContentStyle" Value="{DynamicResource dxHeaderContentControl}" />
    <Setter Property="CellTemplate">
        <Setter.Value>
            <DataTemplate>
                <dxe:TextEdit Name="PART_Editor" Mask="N2" MaskType="Numeric" HorizontalAlignment="Right" MaskUseAsDisplayFormat="True"/>

            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

Also This is for textbox:

<Style TargetType="{x:Type dxe:TextEdit}" x:Key="dxTextEditTutarText"  BasedOn="{StaticResource dxTextEditBaseText}">

    <Setter Property="MaskUseAsDisplayFormat" Value="True" />
    <Setter Property="MaskType" Value="Numeric" />
    <Setter Property="Mask" Value="N2" />
    <Setter Property="HorizontalContentAlignment" Value="Right"/>
</Style>

Solution

  • Change the mask to "N4". In Your code, you set the mask to "N2" twice, which is unnecessary.

    Just change

    <Setter Property="Mask" Value="N2" />
    

    to

    <Setter Property="Mask" Value="N4" />
    

    and remove Mask property in you TextExit (or the other way round)

    For more options see https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100)

    And the DevExpress documentation: https://documentation.devexpress.com/WindowsForms/1498/Controls-and-Libraries/Editors-and-Simple-Controls/Simple-Editors/Concepts/Masks/Mask-Type-Numeric