简体   繁体   中英

XamDataGrid: I have two columns (displaying decimal data): I want one with a “$” sign, and one without. How?

I have two decimal datatype columns; I want them displayed like so:

  • Column 1 ( ColumnWithNoDollarSign ) will have no "$" sign in front of the values
  • Column 2 ( ColumnWithDollarSign ) will have a "$" sign in front of the values

This is what my XAML currently looks like:

<ig:XamDataGrid Name="xamDataGrid"                        
                IsGroupByAreaExpanded="False"
                DataSource="{Binding Rows, Mode=OneWay}">
    <ig:XamDataGrid.Resources>
        <Style TargetType="{x:Type Editors:XamNumericEditor}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="FontSize" Value="12" />
        </Style>
        <Style TargetType="{x:Type Editors:XamCurrencyEditor}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="FontSize" Value="12" />
        </Style>
    </ig:XamDataGrid.Resources>
    <ig:XamDataGrid.FieldLayoutSettings>
        <ig:FieldLayoutSettings AutoGenerateFields="False"/>
    </ig:XamDataGrid.FieldLayoutSettings>
    <ig:XamDataGrid.FieldLayouts>
        <ig:FieldLayout Key="layout">
            <ig:Field Name="ColumnWithNoDollarSign" Label="Column 1"/>
            <ig:Field Name="ColumnWithDollarSign" Label="Column 1"/>
        </ig:FieldLayout>
    </ig:XamDataGrid.FieldLayouts>
</ig:XamDataGrid>

The problem, as I see it, is that the XamCurrencyEditor style I am applying is overriding all decimal columns. I only want it to override one of the decimal columns. How would I go about doing this?

Does the XamNumericEditor represent the format without the $? If so, can you not just specify the style used by each column, ie do:

<ig:XamDataGrid.FieldLayouts>
    <ig:FieldLayout Key="layout">
        <ig:Field Name="ColumnWithNoDollarSign" Label="Column 1" Style="{StaticResource XamNumericEditor}"/>
        <ig:Field Name="ColumnWithDollarSign" Label="Column 1" Style="{StaticResource XamCurrencyEditor}"/>
    </ig:FieldLayout>
</ig:XamDataGrid.FieldLayouts>

Although I would recommend moving all style info to a single file, such as App.xaml, rather than re-defining it in multiple places.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM