/// <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);
                }
            }
예제 #2
0
        /// <summary>
        ///     Creates the visual tree for text based cells.
        /// </summary>
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            TextBlockComboBox comboBox = new TextBlockComboBox();

            ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, comboBox);
            ApplyColumnProperties(comboBox);

            return(comboBox);
        }
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            var comboBox = new TextBlockComboBox();

            comboBox.IsEditable = false;

            ApplyStyle(false, false, comboBox);
            ApplyColumnProperties(comboBox);

            var binding = BindingOperations.GetBinding(this, ComboBox.ItemsSourceProperty);

            ApplyBinding(binding, comboBox, ComboBoxEx.ItemsSourceExProperty);

            return(comboBox);
        }
        /// <summary>
        ///     Creates the visual tree for text based cells.
        /// </summary>
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            TextBlockComboBox comboBox = new TextBlockComboBox();


            // SyncProperties(textBlock);

            //ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, comboBox);
            ApplyColumnProperties(comboBox);

            return(comboBox);

            // PactComboBox textBlock = new PactComboBox();
            // textBlock.FeatureID = 1;
            //// TextBlock textBlock = new TextBlock();

            // SyncProperties(textBlock);

            //// ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, textBlock);
            // ApplyBinding(textBlock, TextBlock.TextProperty);

            // return textBlock;
        }
예제 #5
0
        /// <summary>
        ///     Creates the visual tree for text based cells.
        /// </summary>
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) 
        {
            TextBlockComboBox comboBox = new TextBlockComboBox(); 
 
            ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, comboBox);
            ApplyColumnProperties(comboBox); 

            return comboBox;
        }
        /// <summary>
        ///     Creates the visual tree for text based cells.
        /// </summary>
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            TextBlockComboBox comboBox = new TextBlockComboBox();

               // SyncProperties(textBlock);

            //ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, comboBox);
            ApplyColumnProperties(comboBox);

            return comboBox;

               // PactComboBox textBlock = new PactComboBox();
               // textBlock.FeatureID = 1;
               //// TextBlock textBlock = new TextBlock();

               // SyncProperties(textBlock);

               //// ApplyStyle(/* isEditing = */ false, /* defaultToElementStyle = */ false, textBlock);
               // ApplyBinding(textBlock, TextBlock.TextProperty);

               // return textBlock;
        }