1

我一直在使用工具包中的 DataForm,现在我意识到 IEditableObject 接口显然存在问题。绑定到具有 2 个子对象的对象的数据表单。父对象和 2 个子对象的所有字段都在同一个表单上。当我从父对象修改数据字段时,“确定”按钮变为启用状态,但是当我使用子对象中的 3 个字段中的 2 个时,“确定”按钮保持禁用状态。我试图调查这些领域之间的差异,它们似乎都是一样的,有人面临同样的问题吗?

在下面的示例中,字段 NumberWrapper 和 LabelWrapper 属于父对象,然后 Stc1Wrapper 是一个对象,它是父对象的一部分,字段标签会触发确定按钮,但电话号码和转移代码字段不会。Stc1Wrapper 的 3 个字段的底层实现看起来都相同。我被困在这里我找不到有关此数据表单控件的正确 MSDN 文档,因为它来自不幸的工具包。

<toolkit:DataForm Grid.Column="1" 
                          Margin="0,94,0,0" 
                          Width="350"
                          Name="EsnDataForm" 
                          Header="Esn Item"
                          AutoGenerateFields="False" 
                          CurrentItem="{Binding ElementName=MyGrid, Path=SelectedItem,Mode=TwoWay}" 
                          AutoEdit="False" 
                          AutoCommit="False"
                          CommandButtonsVisibility="Cancel,Edit,Commit"
                          CommitButtonContent="Save"
                          CancelButtonContent="Cancel">
            <toolkit:DataForm.NewItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                            <RowDefinition Height="32" />
                        </Grid.RowDefinitions>
                        <toolkit:DataField Label="Number" IsReadOnly="True" >
                            <TextBox Text="{Binding NumberWrapper,Mode=TwoWay}" MaxLength="9" Width="120" IsReadOnly="True" />
                        </toolkit:DataField>
                        <toolkit:DataField Label="Label" Grid.Row="1" >
                            <TextBox Name="NameBox" Text="{Binding LabelWrapper,Mode=TwoWay}" MaxLength="32" Width="120" />
                        </toolkit:DataField>
                        <toolkit:DataField Label="Sub Label" Grid.Row="2" >
                            <TextBox Name="SubLabelBox" Text="{Binding PrimaryPsapLabelWrapper,Mode=TwoWay}" MaxLength="32" Width="120" />
                        </toolkit:DataField><toolkit:DataField Label="Label" Margin="-50,1,1,1" >
                            <TextBox Name="Stc1LabelBox" Text="{Binding Stc1Wrapper.LabelWrapper, Mode=TwoWay}" MaxLength="32" Width="120" />
                        </toolkit:DataField>
                        <toolkit:DataField Label="Telephone Number" Margin="-50,1,1,1" >
                            <TextBox Name="Stc1TelephoneBox" Text="{Binding Stc1Wrapper.TnWrapper, Mode=TwoWay}" MaxLength="10" Width="120" />
                        </toolkit:DataField>
                        <toolkit:DataField Label="Transfer Code" Margin="-50,1,1,1" >
                            <TextBox Name="Stc1TransferCodeBox" Text="{Binding Stc1Wrapper.TransferCodeWrapper, Mode=TwoWay}" Width="120" />
                        </toolkit:DataField>
                    [...]

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnore]
    public string TransferCodeWrapper
    {
        get
        {
            return this.TransferCode;
        }
        set
        {
            ValidateRequired("TransferCodeWrapper", value, "Transfer Code is mandatory");
            ValidateRegularExpression("TransferCodeWrapper", value, @"^[\*]\d{1,3}$", "The format should be * followed by 1 to 3 digits");
            this.TransferCode = value;
            this.RaisePropertyChanged("TransferCodeWrapper");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnore]
    public string TnWrapper
    {
        get
        {
            return this.Tn;
        }
        set
        {
            ValidateRequired("TnWrapper", value, "Telephone number is mandatory when Type is Telephone Number");
            ValidateRegularExpression("TnWrapper", value, @"^\d{10}$", "The telephone number should be 10 digits");
            this.Tn = value;
            this.RaisePropertyChanged("TnWrapper");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnore]
    public string LabelWrapper
    {
        get
        {
            return this.Label;
        }
        set
        {
            ValidateRequired("LabelWrapper", value, "Label is required");
            ValidateRegularExpression("LabelWrapper", value, @"^[\w-_ ]$+", "Characters allowed (a-z,A-Z,0-9,-,_, )");
            this.Label = value;
            this.RaisePropertyChanged("LabelWrapper");
        }
    }
4

0 回答 0