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]
public string Name;
Binding触发错误,因为默认情况下Name是空的...我的造型错了吗?
答案 0 :(得分:0)
我后来发现了我的错误,它对我有用,修复它,你的类应该继承实体类......
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");
}
}
}
}
像这样......