public class SfDataGridBehavior: Behavior<SfDataGrid>
{
protected override void OnAttached()
{
TemplateViewDefinition templateViewDefinition = new TemplateViewDefinition();
templateViewDefinition.RowTemplate = GetDataTemplate();
this.AssociatedObject.DetailsViewDefinition.Add(templateViewDefinition);
}
private DataTemplate GetDataTemplate()
{
FrameworkElementFactory comboBoxAdv = new FrameworkElementFactory(typeof(ComboBoxAdv));
comboBoxAdv.SetValue(ComboBoxAdv.HorizontalAlignmentProperty, HorizontalAlignment.Center);
comboBoxAdv.SetValue(ComboBoxAdv.VerticalAlignmentProperty, VerticalAlignment.Center);
comboBoxAdv.SetValue(ComboBoxAdv.SelectedValueProperty, "ProductName");
comboBoxAdv.SetValue(ComboBoxAdv.DisplayMemberPathProperty, "ProductName");
comboBoxAdv.SetValue(ComboBoxAdv.WidthProperty, 200d);
Binding binding = new Binding();
binding.Path = new PropertyPath("DataContext.OrderList");
binding.ElementName = this.AssociatedObject.Name;
comboBoxAdv.SetBinding(ComboBoxAdv.ItemsSourceProperty, binding);
var dataTemplate = new DataTemplate() { VisualTree = comboBoxAdv };
return dataTemplate;
}
} |