Silverlight中数据网格中同一标头中的多种控件

时间:2009-09-21 14:39:18

标签: silverlight templates datagrid controls

我想使用DataGrid在Silverlight中设计属性窗口。它将有两个标题列。值标头可以具有不同类型的控件。它可能有组合框,文本框和其他控件。 这是datagrid的视图。

  1. 名称--------------控件的类型(要显示的控件)
  2. DisplayText -------文本框
  3. 类型--------------组合框
  4. 的IsEnabled ---------复选框
  5. 如果在数据网格中不可能,那么请建议其他方法来实现相同的目标。

2 个答案:

答案 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;
    }