// If a DataGridCollectionViewBase is used, get the ItemProperties it defines to be able to retreive DataGridForeignKeyDescription for each of them // to get the auto-detected ForeignKey ItemsSource (if any). // If a DataGridCollectionViewBase is not used, the ItemsSource must be manually specified on each Column in order to correctly display/edit the Data internal static void UpdateColumnsForeignKeyConfigurationsFromDataGridCollectionView(Dictionary <string, ColumnBase> columns, DataGridItemPropertyCollection itemProperties, bool autoCreateForeignKeyConfigurations) { if (itemProperties == null) { return; } foreach (DataGridItemPropertyBase itemProperty in itemProperties) { DataGridForeignKeyDescription description = itemProperty.ForeignKeyDescription; if (description == null) { continue; } ColumnBase column; columns.TryGetValue(itemProperty.Name, out column); ForeignKeyConfiguration.SynchronizeForeignKeyConfigurationFromForeignKeyDescription(column as Column, description, autoCreateForeignKeyConfigurations); } }
private void SetForeignKeyConfiguration(ForeignKeyConfiguration value) { this.SetValue(CellEditorContext.ForeignKeyConfigurationPropertyKey, value); }
internal CellEditorContext(ColumnBase parentColumn, ForeignKeyConfiguration configuration) { this.SetParentColumn(parentColumn); this.SetForeignKeyConfiguration(configuration); }
private void RefreshDefaultScrollTipContentTemplate() { DataGridContext itemContext = DataGridControl.GetDataGridContext(this); if (itemContext == null) { return; } DataGridControl parentGridControl = itemContext.DataGridControl; if ((parentGridControl == null) || (parentGridControl.ScrollViewer == null)) { return; } ColumnCollection columnCollection = itemContext.Columns; if (columnCollection == null) { return; } Column mainColumn = columnCollection.MainColumn as Column; if (mainColumn == null) { return; } Nequeo.Wpf.DataGrid.Views.UIViewBase uiViewBase = parentGridControl.GetView() as Nequeo.Wpf.DataGrid.Views.UIViewBase; if (uiViewBase == null) { return; } // The ScrollTip.ContentTemplate will now be set. This is to avoid // a null ContentTemplate when the ColumnsCollection update its // MainColumn after the template is applied this.ScrollTipContentTemplateNeedsRefresh = false; ForeignKeyConfiguration configuration = mainColumn.ForeignKeyConfiguration; // Do not create default template only when none was created before and a template already exists if ((!this.UsingDefaultScrollTipContentTemplate) && (uiViewBase.ScrollTipContentTemplate != null)) { if (configuration != null) { this.ContentTemplate = configuration.DefaultScrollTipContentTemplate; } else { // Clear the value in case we previously affected it this.ClearValue(ScrollTip.ContentTemplateProperty); // Set the default Binding values this.SetBinding(ScrollTip.ContentTemplateProperty, this.DefaultScrollTipContentTemplateBinding); this.SetBinding(ScrollTip.ContentTemplateSelectorProperty, this.DefaultScrollTipContentTemplateSelectorBinding); } } else { // A default ContentTemplate template is created using MainColumn as displayed data this.UsingDefaultScrollTipContentTemplate = true; // If a configuration was found, the default ContentTemplate will // be used to convert Content to Foreign value and // it will use the ScrollTipContentTemplate defined on UIViewBase // if any if (configuration == null) { // Disable warning for DisplayMemberBinding when internaly used #pragma warning disable 618 BindingBase displayMemberBinding = mainColumn.DisplayMemberBinding; #pragma warning restore 618 FrameworkElementFactory contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter)); contentPresenter.SetValue(ContentPresenter.NameProperty, "defaultScrollTipDataTemplateContentPresenter"); contentPresenter.SetBinding(ContentPresenter.ContentProperty, displayMemberBinding); contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, this.DefaultCellContentTemplateBinding); contentPresenter.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, this.DefaultCellContentTemplateSelectorBinding); DataTemplate template = new DataTemplate(); template.VisualTree = contentPresenter; template.Seal(); this.ContentTemplate = template; } else { this.SetBinding(ContentPresenter.ContentTemplateProperty, this.DefaultCellContentTemplateBinding); this.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, this.DefaultCellContentTemplateSelectorBinding); this.ContentTemplate = configuration.DefaultScrollTipContentTemplate; } } }
public override object GetValueFromKey(object key, ForeignKeyConfiguration configuration) { // When the Key changes, try to find the data row that has the new key. // If it is not found, return null. DataView dataView = configuration.ItemsSource as DataView; if (dataView == null) { DataTable dataTable = configuration.ItemsSource as DataTable; if (dataTable != null) { dataView = dataTable.DefaultView; } } if (dataView == null) { return(key); } string valuePath = configuration.ValuePath; if (string.IsNullOrEmpty(valuePath)) { return(key); } dataView.Sort = valuePath; DataRowView dataRow; int index = -1; if ((key != null) && (!object.Equals(string.Empty, key))) { try { index = dataView.Find(key); } catch (Exception) { } } if (index == -1) { dataRow = null; } else { dataRow = dataView[index]; } object value = dataRow; // Use the DisplayMemberPath if defined if (dataRow != null) { if (!string.IsNullOrEmpty(configuration.DisplayMemberPath)) { value = dataRow[configuration.DisplayMemberPath]; } } return(value); }
public static void RemoveListener(ForeignKeyConfiguration source, IWeakEventListener listener) { CurrentManager.ProtectedRemoveListener(source, listener); }
public virtual object GetKeyFromValue(object value, ForeignKeyConfiguration configuration) { return(value); }
public virtual object GetValueFromKey(object key, ForeignKeyConfiguration configuration) { return(key); }