Ejemplo n.º 1
0
            /// <summary>
            ///     Property changed callback for DataContext property
            /// </summary>
            private static void OnDataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                // Selector has a bug regarding DataContext change and SelectedItem property,
                // where if the SelectedItem due to old DataContext is a valid item in ItemsSource
                // but the SelectedItem due to new DataContext is not a valid item in ItemsSource,
                // the SelectedIndex remains that of old context instead of changing to -1.
                // This method is a workaround to that problem, since it is of high impact to DataGrid.
                TextBlockComboBox combo = (TextBlockComboBox)d;
                bool isLocalValue       = (DependencyPropertyHelper.GetValueSource(combo, SelectedItemProperty).BaseValueSource == BaseValueSource.Local);

                if (isLocalValue)
                {
                    // Clear the selection and re-apply the binding.
                    BindingBase binding = BindingOperations.GetBindingBase(combo, SelectedItemProperty);
                    if (binding != null)
                    {
                        combo.ClearValue(SelectedItemProperty);
                        DataGridPactComboBoxColumn.ApplyBinding(binding, combo, SelectedItemProperty);
                    }
                }
                else
                {
                    // Clear the selection by setting the local value
                    // and re-evaluate the property by clearing the local value.
                    combo.SelectedItem = null;
                    combo.ClearValue(SelectedItemProperty);
                }
            }
Ejemplo n.º 2
0
        private static DataGridColumn CreateColumn(DataGrid gridView, object columnSource)
        {
            DgColumn col = columnSource as DgColumn;
            if (col.Control == "TextBlock")
            {
                DataGridTextColumn column = new DataGridTextColumn();
                column.Binding = new Binding(col.DisplayMember);
                return column;
            }
            else if (col.Control == "PactComboBox")
            {
                DataGridPactComboBoxColumn column = new DataGridPactComboBoxColumn();
                column.Binding = new Binding(col.DisplayMember);
                column.FeatureID = Convert.ToInt32(col.Param);
                column.SelectedValueBinding = new Binding(col.DisplayMember + "_Key");
                return column;
            }
            else if (col.Control == "DatePicker")
            {
                DataGridDateColumn column = new DataGridDateColumn();
                column.Binding = new Binding(col.DisplayMember);
               // column.SelectedValueBinding = new Binding(col.DisplayMember + "_Key");
                return column;
            }
            else//if (col.ColumnType == "TextBox")
            {
                DataGridTextColumn column = new DataGridTextColumn();
                column.Binding = new Binding(col.DisplayMember);
                return column;
            }
            //if (col.ColumnType == "MultiCombo")
            //{
            //    CustDataGridComboBoxColumn combcolumn = new CustDataGridComboBoxColumn();
            //    combcolumn.Header = col.HeaderText;
            //    combcolumn.DisplayMemberPath = col.DisplayMember;
            //    combcolumn.SelectedValuePath = col.ValueMember;
            //    combcolumn.SelectedValueBinding = new Binding(col.ValueBinding);

            //    combcolumn.ItemsSource = col.Source;
            //    combcolumn.Width = col.width;

            //    for (int i = 0; i < col.Columns.Count; i++)
            //    {
            //        GridViewColumn e = new GridViewColumn();
            //        e.Header = col.Columns[i].HeaderText;
            //        e.DisplayMemberBinding = new Binding(col.Columns[i].DisplayMember);
            //        combcolumn.Columns.Add(e);
            //    }

            //    return combcolumn;

            //}

            return null;
        }