如何从另一个字段屏蔽 WPF Infragistics NumericField [英] How to Mask a WPF Infragistics NumericField from another field

查看:24
本文介绍了如何从另一个字段屏蔽 WPF Infragistics NumericField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要屏蔽的字段,但屏蔽格式可能因实际记录而异.该表包含规范记录,每种类型的规范可以具有不同的精度.我无法在 Xaml 代码中设置此精度.

I have a field I need masked but the mask format can differ depending upon the actual record. The table contains specification records and each type of spec can have a different precision. I am unable to set this precision in Xaml code.

我尝试了以下方法:

 <inf:NumericField Name="ResultQty" Label="Test Results" Width="100" HorizontalContentAlignment="Center" Mask="{Binding FormatDesc}"/>

<inf:NumericField Name="ResultQty" Label="Test Results" Width="100" HorizontalContentAlignment="Center" Format="{Binding FormatDesc}"/>

FormatDesc 为该记录返回 ###,##0.000,ResultQty 为 0.2720.它应该显示为 0.272,但显示为 0.27.

FormatDesc returns ###,##0.000 for this record and ResultQty is 0.2720. It should display as 0.272 but is displaying as 0.27.

有没有办法将 FormatDesc 属性绑定到 Xaml 中的字段,或者我应该寻找不同的方法?

Is there a way to bind the FormatDesc property to the field in the Xaml or should I be looking for a different approach?

推荐答案

Infragistics 网站上有类似问题的以下解释:

XamDataGrid 中的字段不是 WPF 中的可视元素,因此不能直接绑定到数据上下文,因为它们不公开一个继承自 FrameworkElement.

Fields in the XamDataGrid are not visual elements in WPF, and as such cannot be bound directly to a data context, as they do not expose one inherited from FrameworkElement.

为了绑定非可视元素的属性XamDataGridFieldFieldSettingsFieldLayoutSettings,我建议使用 FieldBinding.你可以阅读FieldBindingXamDataGrid 中:https://www.infragistics.com/help/wpf/xamdatagrid-binding-field-fieldlayout-to-mvvm.

In order to bind the properties of the non-visual elements of the XamDataGrid such as Field, FieldSettings, or FieldLayoutSettings, I would recommend using a FieldBinding. You can read about FieldBinding in the XamDataGrid here: https://www.infragistics.com/help/wpf/xamdatagrid-binding-field-fieldlayout-to-mvvm.

因此,建议在 Infragistics 站点上使用 FieldBinding 标记扩展,以便将属性绑定到 FieldFieldSettings 或 <代码>FieldLayoutSettings.
虽然提到的帖子包含使用 MVVM 模式的示例,但 FieldBinding 标记扩展可以在没有它的情况下使用.

So, on the Infragistics site is recommended to use FieldBinding markup extension in order to bind properties to the Field, FieldSettings, or FieldLayoutSettings.
While mentioned post includes example that uses the MVVM pattern the FieldBinding markup extension can be used without it.

例如,假设使用以下数据模型:

public class TestReportProvider : ObservableModel
{
    public TestReportProvider()
    {         
    }

    public string QtyFormat { get; set; } = "###,##0.000";

    private ObservableCollection<Test> _tests = null;
    public ObservableCollection<Test> Tests
    {
        get
        {
            return this._tests;
        }
        set
        {
            if (this._tests != value)
            {
                this._tests = value;
                this.OnPropertyChanged("Tests");
            }
        }
    }
    //… 
}

在代码隐藏中设置DataContext:

public partial class FieldBindingExample : Window
{
    public TestReportProvider ReportData = new TestReportProvider();
    public FieldBindingExample()
    {        
        InitializeComponent();
        DataContext = ReportData;
    }
    //…
}

现在为 XamDataGrid 设置 DataSource 并使用 FieldBinding 标记扩展:

Now set DataSource for the XamDataGrid and use the FieldBinding markup extension:

<Grid>
    <igDP:XamDataGrid DataSource="{Binding Path=Tests}" AutoFit="True">
        <igDP:XamDataGrid.FieldLayoutSettings>            
            <igDP:FieldLayoutSettings AutoGenerateFields="False"
                                      AutoFitMode="Always" 
                                      AddNewRecordLocation="OnTopFixed"/>                   
            </igDP:XamDataGrid.FieldLayoutSettings>

            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>    
                        <igDP:TextField Name="TestDescription" Label="Test Description" />
                        <igDP:NumericField Name="Result" Label="Result" />
                        <igDP:NumericField Name="Average" Label="Average Deviation" 
                                           Format="{igDP:FieldBinding QtyFormat}" />                            
                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>         
</Grid>

这篇关于如何从另一个字段屏蔽 WPF Infragistics NumericField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆