tags:

views:

551

answers:

1

DataFrom works fine with AutoGenerateFields and no styles, but when I add a textbox style to the DataFormTextField's EditingElementStyle like this

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>

and this

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 });

I want the form to start in Edit mode without having to click a button. But since Name is required

[Required]

public string Name;

The Binding triggers an error because Name is empty by default... Is my styling wrong?

A: 

I later discovered my error, well it worked for me, to fix it your class should inherit the Entity Class...

 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");
            }
        }
    }
}

Something like that...

Fredrick