TemplateColumn中的Combobox填充RowHeight

时间:2016-06-30 09:33:03

标签: c# wpf combobox datagrid datagridtemplatecolumn

我在代码中创建了DataGridTemplateColumn ComboBox。当我更改DataGridRow的高度时,我希望ComboBox始终填充Cell。但是现在我的ComboBox始终保持相同的高度。它适用于Width。这是我到目前为止所尝试的: (有关信息的全部代码)

ItemsPanelTemplate IPT = null;
        DataGridTemplateColumn DGTC = new DataGridTemplateColumn();
        DataTemplate DataTMP = null;
        Binding bind = new Binding(strPropertyname);
        FrameworkElementFactory cboFactory = new FrameworkElementFactory(typeof(ComboBox));

        cboFactory.SetValue(ComboBox.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
        cboFactory.SetValue(ComboBox.VerticalAlignmentProperty, VerticalAlignment.Stretch);
        cboFactory.SetValue(ComboBox.ItemsSourceProperty, DTCBOSource.DefaultView);
        cboFactory.SetValue(ComboBox.IsEditableProperty, false);
        cboFactory.SetValue(ComboBox.IsTextSearchEnabledProperty, true);
        cboFactory.SetValue(ComboBox.IsEnabledProperty, !blnIsReadOnly);
        cboFactory.SetValue(ComboBox.SelectedValuePathProperty, DTCBOSource.Columns[0].ColumnName);
        cboFactory.SetValue(ComboBox.DisplayMemberPathProperty, DTCBOSource.Columns[1].ColumnName);

        Binding bHeight = new Binding();
        bHeight.Source = _DGSource;
        bHeight.Path = new PropertyPath("RowHeight");
        bHeight.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        cboFactory.SetValue(ComboBox.HeightProperty, bHeight);

        cboFactory.AddHandler(ComboBox.GotFocusEvent, new RoutedEventHandler(DG_EditingElementEnter));
        cboFactory.AddHandler(ComboBox.LostFocusEvent, new RoutedEventHandler(DG_EditingElementLeave));

        IPT = (ItemsPanelTemplate)(Application.Current.TryFindResource("CBOVirtualPanel"));
        if (IPT != null)
        {
            cboFactory.SetValue(ComboBox.ItemsPanelProperty, IPT);
        }

        bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        bind.NotifyOnTargetUpdated = true;


        //bind.Mode = BindingMode.TwoWay;

        cboFactory.SetBinding(ComboBox.SelectedValueProperty, bind);



        DataTMP = new DataTemplate();
        DataTMP.VisualTree = cboFactory;
        DGTC.CellTemplate = DataTMP;
        DGTC.SortMemberPath = strPropertyname;
        //_DGSource.TargetUpdated += DG_CellValueChanged_Event;
        return DGTC;

0 个答案:

没有答案