我想使用DataGrid在Silverlight中设计属性窗口。它将有两个标题列。值标头可以具有不同类型的控件。它可能有组合框,文本框和其他控件。 这是datagrid的视图。
如果在数据网格中不可能,那么请建议其他方法来实现相同的目标。
答案 0 :(得分:0)
你看过DataForm吗?我不确定你为什么要在DataGrid中执行上述操作。
答案 1 :(得分:0)
我使用了一个返回控件的转换器。
转换器创建了对源对象的数据绑定
datagrid数据源是IEnumerable<PropertyPresenter>
public class PropertyPresenter
{
public PropertyInfo PropertyInfo { get; set; }
public object Source { get; set; }
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
FrameworkElement Control = null;
var presenter = value as PropertyPresenter;
Binding binding = new Binding(presenter.PropertyInfo.Name);
binding.Mode = presenter.PropertyInfo.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay;
binding.Source = presenter.Source;
if(presenter.PropertyInfo.PropertyType == typeof(bool))
{
Control = new CheckBox();
Control.HorizontalAlignment = HorizontalAlignment.Right;
Control.SetBinding(CheckBox.IsCheckedProperty, binding);
}
return Control;
}