我想你想與控制(帶有一個Silverlight的DataForm在RIA)添加StackPanel的一個特定的屬性
第一次捕捉事件AutoGeneratingField
即
this.myDataForm.AutoGeneratingField +=new EventHandler<DataFormAutoGeneratingFieldEventArgs>(AutoGeneratingFieldHandler);
然後在事件處理程序
void AutoGeneratingFieldHandler(object sender, DataFormAutoGeneratingFieldEventArgs e)
{
if(e.PropertyName=="myPropertyNameWithCustomField")
{
StackPanel pnl = new StackPanel();
pnl.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
ComboBox cbo = new ComboBox();
//setup binding to base
Binding b = new Binding("myPropertyNameWithCustomField") { Mode = BindingMode.TwoWay };
cbo.SetBinding(ComboBox.SelectedValueProperty, b);
//add the combo to the stackpanel
pnl.Children.Add(cbo);
//replace the autogenerated content with the stackpanel
e.Field.Content=pnl;
e.Field.IsRequired=true;
}
}
這應該讓你開始用自定義控件設置DataForm。