编辑嵌套对象时,Dataform OK / SAVE按钮保持禁用状态

时间:2012-05-02 17:53:59

标签: c# wpf silverlight xaml dataform

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

在下面的示例中,字段NumberWrapper和LabelWrapper属于父对象,然后Stc1Wrapper是一个对象,它是父对象的一部分,字段标签DOES触发ok按钮,但电话号码和传输代码字段不是。 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");
        }
    }

0 个答案:

没有答案