【问题标题】:Starting DataForm in edit mode在编辑模式下启动 DataForm
【发布时间】:2009-05-08 01:08:55
【问题描述】:

DataFrom 可以很好地使用 AutoGenerateFields 并且没有样式,但是当我像这样将文本框样式添加到 DataFormTextField 的 EditingElementStyle 时

Style x:Key="FieldTextBoxStyle" TargetType="TextBox">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TextBox">
                <Grid x:Name="RootElement">
                              <Grid.Resources>
                                    <Storyboard x:Key="Normal State"/>
                                    <Storyboard x:Key="Focused State"/>
                                </Grid.Resources>
                                <ScrollViewer x:Name="ContentElement"  Background="Transparent" Padding="{TemplateBinding Padding}" Margin="1,1,1,1">

                                </ScrollViewer>

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

还有这个

DataForm dForm = new DataForm() { AutoGenerateFields = false, AutoEdit = true, AutoCommit = true, CommandButtonsVisibility = DataFormCommandButtonsVisibility.None, Foreground = new SolidColorBrush(Colors.Black), Header = "Basic Infomation" };

dForm.Fields.Add(new DataFormTextField() { FieldLabelContent = "Company Name", Binding = new Binding("Name"), EditingElementStyle = Resources["FieldTextBoxStyle"] as Style });

我希望表单以编辑模式启动,而无需单击按钮。但是由于名称是必需的

[Required]

公共字符串名称;

Binding 触发错误,因为 Name 默认为空...我的样式是否错误?

【问题讨论】:

  • 我遇到了类似的问题。我将我的数据表单绑定到具有必填字段的对象。在自动编辑模式下,第一个字段的验证会自动触发。

标签: c# silverlight


【解决方案1】:

我后来发现了我的错误,它对我有用,修复它你的类应该继承实体类...

 public class FixError : System.Windows.Ria.Data.Entity
{
    private string _Name;

    [Required]
    public string Name
    {
        get
        {
            return this._Name;
        }
        set
        {
            if ((this._Name != value))
            {
                this.ValidateProperty("Name", value);
                this.RaiseDataMemberChanging("Name");
                this._Name = value;
                this.RaiseDataMemberChanged("Name");
            }
        }
    }
}

类似的...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多