设置 XamDataGrid 字段的最小值和最大值

Setting the Min and Max values of a XamDataGrid Field

所以我有一个带有百分比字段的 XamDataGrid

<igWPF:XamDataGrid  DataSource="{Binding Data}" DataValueChanged="XamDataGrid_DataValueChanged">
   <igWPF:XamDataGrid.FieldLayoutSettings>
      <igWPF:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="False" AddNewRecordLocation="OnBottomFixed" />
   </igWPF:XamDataGrid.FieldLayoutSettings>
   <igWPF:XamDataGrid.FieldLayouts>
      <igWPF:FieldLayout>
         <igWPF:Field Name="Percent" />
      </igWPF:FieldLayout>
   </igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>

我需要将百分比字段设置为最大值为 100。我该怎么做?

您可以使用数字字段,即 int / Int32 并将字段编辑器类型设置为 XamNumericEditor。然后,您可以定义一个 ValueConstraint 来指定最小值和最大值。

<igWPF:XamDataGrid  DataSource="{Binding Data}" DataValueChanged="XamDataGrid_DataValueChanged">
   <igWPF:XamDataGrid.FieldLayoutSettings>
      <igWPF:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="False" AddNewRecordLocation="OnBottomFixed" />
   </igWPF:XamDataGrid.FieldLayoutSettings>
   <igWPF:XamDataGrid.FieldLayouts>
      <igWPF:FieldLayout>
         <igWPF:Field Name="Percent" DataType="{x:Type sys:Int32}" BindingType="Unbound">
            <igWPF:Field.Settings>
               <igWPF:FieldSettings EditorType="{x:Type igEditors:XamNumericEditor}">
                  <igWPF:FieldSettings.EditorStyle>
                     <Style TargetType="{x:Type igEditors:XamNumericEditor}">
                        <Setter Property="ValueConstraint">
                           <Setter.Value>
                              <igEditors:ValueConstraint MinInclusive="0" MaxInclusive="100" />
                           </Setter.Value>
                        </Setter>
                     </Style>
                  </igWPF:FieldSettings.EditorStyle>
               </igWPF:FieldSettings>
            </igWPF:Field.Settings>
         </igWPF:Field>
      </igWPF:FieldLayout>
   </igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>

有关详细信息,请参阅 Configuring XamNumericEditor 和其他代码示例: