public override UIElement GenerateUI() { Thickness sep = new Thickness(5, 0, 0, 0); modifier = new ListLogicModifier() { Margin = sep, VerticalContentAlignment = VerticalAlignment.Center }; modifier.SelectionChanged += GenerateSelectionChangedHandler("modifier"); options = new MultiComboBox() { ItemString = Optiontype, ItemsSource = OptionList, Margin = sep }; options.SelectionChanged += GenerateSelectionChangedHandler("options"); StackPanel spMain = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 0, 30, 0), }; spMain.Children.Add(new TextBlock() { Text = Verb, VerticalAlignment = VerticalAlignment.Center }); spMain.Children.Add(modifier); spMain.Children.Add(new TextBlock() { Text = Optiontype.Pluralize() + ":", VerticalAlignment = VerticalAlignment.Center, Margin = sep }); spMain.Children.Add(options); return(spMain); }
public OptionColumnInfo(DataGridColumn column, DataGridExtend grid) { if (column == null) return; Column = column; if (column is DataGridTemplateColumn) { var boundColumn = column as DataGridTemplateColumn; if (boundColumn != null) { DataTemplate dt = boundColumn.CellTemplate as DataTemplate; if (dt != null) { if (dt.DataType != null) { string dataType = dt.DataType.ToString(); TemplateColumnType templateType = (TemplateColumnType)Enum.Parse(typeof(TemplateColumnType), dataType); System.Windows.Data.Binding binding = new Binding(); switch (templateType) { case TemplateColumnType.HyperLink: StackPanel sp = dt.LoadContent() as StackPanel; TextBlock tb = sp.Children[3] as TextBlock; InlineUIContainer il = tb.Inlines.FirstInline as InlineUIContainer; Label lbl = il.Child as Label; Run r = lbl.Content as Run; binding = BindingOperations.GetBinding(r, Run.TextProperty); break; case TemplateColumnType.TextBlock: TextBlock tb1 = dt.LoadContent() as TextBlock; binding = BindingOperations.GetBinding(tb1, TextBlock.TextProperty); break; case TemplateColumnType.CheckBox: CheckBox cb = new CheckBox(); if (dt.LoadContent() is CheckBox) { cb = dt.LoadContent() as CheckBox; } else if(dt.LoadContent() is Grid) { Grid gd = dt.LoadContent() as Grid; if (gd.Children.Count > 1) { cb = gd.Children[1] as CheckBox; } } if (cb.IsThreeState) { IsSpecialState = true; binding = BindingOperations.GetBinding(cb, CheckBox.ContentProperty); } else { binding = BindingOperations.GetBinding(cb, CheckBox.IsCheckedProperty); } break; case TemplateColumnType.MultiComboBox: try { MultiComboBox multiCbb = dt.LoadContent() as MultiComboBox; binding = BindingOperations.GetBinding(multiCbb, MultiComboBox.TextProperty); } catch (Exception ex) { binding = null; } break; case TemplateColumnType.ComboBox: Grid gd2 = dt.LoadContent() as Grid; ComboBox com = gd2.Children[0] as ComboBox; if (!string.IsNullOrWhiteSpace(com.DisplayMemberPath)) { binding = BindingOperations.GetBinding(com, ComboBox.SelectedItemProperty); StringPath = com.DisplayMemberPath; } else { binding = BindingOperations.GetBinding(com, ComboBox.SelectedItemProperty); } break; } if (binding != null && binding.Path != null && !string.IsNullOrWhiteSpace(binding.Path.Path)) { System.Reflection.PropertyInfo propInfo = null; if (!string.IsNullOrWhiteSpace(StringPath)) { System.Reflection.PropertyInfo propInfo2 = null; if (grid.FilterType != null) propInfo2 = grid.FilterType.GetProperty(binding.Path.Path); propInfo = propInfo2.PropertyType.GetProperty(StringPath); } else { if (grid.FilterType != null) propInfo = grid.FilterType.GetProperty(binding.Path.Path); } //if (propInfo != null) //{ IsValid = propInfo != null ? true : false; PropertyPath = binding.Path.Path; Converter = binding.Converter; PropertyType = propInfo != null ? propInfo.PropertyType : typeof(string); if (Converter != null) { PropertyConvertType = Converter.Convert(null, null, null, null).GetType(); } ConverterCultureInfo = binding.ConverterCulture; ConverterParameter = binding.ConverterParameter; //} //else //{ //} } } } } else if (column.SortMemberPath != null && column.SortMemberPath.Length > 0) { PropertyPath = column.SortMemberPath; PropertyType = grid.FilterType.GetProperty(column.SortMemberPath).PropertyType; } } else { var boundColumn = column as DataGridBoundColumn; if (boundColumn != null) { System.Windows.Data.Binding binding = boundColumn.Binding as System.Windows.Data.Binding; if (binding.Path == null) return; if (binding != null && !string.IsNullOrWhiteSpace(binding.Path.Path)) { System.Reflection.PropertyInfo propInfo = null; if (grid.FilterType != null) propInfo = grid.FilterType.GetProperty(binding.Path.Path); if (propInfo != null) { IsValid = true; PropertyPath = binding.Path.Path; Converter = binding.Converter; PropertyType = propInfo != null ? propInfo.PropertyType : typeof(string); if (Converter != null) { PropertyConvertType = Converter.Convert(null, null, null, null) == null ? null : Converter.Convert(null, null, null, null).GetType(); } ConverterCultureInfo = binding.ConverterCulture; ConverterParameter = binding.ConverterParameter; } else { //if (System.Diagnostics.Debugger.IsAttached && System.Diagnostics.Debugger.IsLogging()) // System.Diagnostics.Debug.WriteLine("Jib.WPF.Controls.DataGrid.JibGrid: BindingExpression path error: '{0}' property not found on '{1}'", binding.Path.Path, boundObjectType.ToString()); } } } else if (column.SortMemberPath != null && column.SortMemberPath.Length > 0) { PropertyPath = column.SortMemberPath; PropertyType = grid.FilterType.GetProperty(column.SortMemberPath).PropertyType; } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { foreach (var item in FilterSelectedItem.Grid.Columns) { if (item.Visibility == Visibility.Collapsed) { continue; } Binding BindingSelected = null; string StringPath = ""; if (item is DataGridTemplateColumn) { var boundColumn = item as DataGridTemplateColumn; if (boundColumn != null) { DataTemplate dt = boundColumn.CellTemplate as DataTemplate; if (dt != null) { if (dt.DataType != null) { string dataType = dt.DataType.ToString(); TemplateColumnType templateType = (TemplateColumnType)Enum.Parse(typeof(TemplateColumnType), dataType); switch (templateType) { case TemplateColumnType.HyperLink: StackPanel sp = dt.LoadContent() as StackPanel; TextBlock tb = sp.Children[3] as TextBlock; InlineUIContainer il = tb.Inlines.FirstInline as InlineUIContainer; Label lbl = il.Child as Label; Run r = lbl.Content as Run; BindingSelected = BindingOperations.GetBinding(r, Run.TextProperty); break; case TemplateColumnType.TextBlock: TextBlock tb1 = dt.LoadContent() as TextBlock; BindingSelected = BindingOperations.GetBinding(tb1, TextBlock.TextProperty); break; case TemplateColumnType.CheckBox: CheckBox cb = new CheckBox(); if (dt.LoadContent() is CheckBox) { cb = dt.LoadContent() as CheckBox; } else if (dt.LoadContent() is Grid) { Grid gd1 = dt.LoadContent() as Grid; if (gd1.Children.Count > 1) { cb = gd1.Children[1] as CheckBox; } } if (cb.IsThreeState) { //IsSpecialState = true; BindingSelected = BindingOperations.GetBinding(cb, CheckBox.ContentProperty); } else { BindingSelected = BindingOperations.GetBinding(cb, CheckBox.IsCheckedProperty); } break; case TemplateColumnType.MultiComboBox: try { MultiComboBox multiCbb = dt.LoadContent() as MultiComboBox; BindingSelected = BindingOperations.GetBinding(multiCbb, MultiComboBox.TextProperty); } catch (Exception ex) { BindingSelected = null; } break; case TemplateColumnType.ComboBox: Grid gd = dt.LoadContent() as Grid; ComboBox com = gd.Children[0] as ComboBox; if (!string.IsNullOrWhiteSpace(com.DisplayMemberPath)) { BindingSelected = BindingOperations.GetBinding(com, ComboBox.SelectedItemProperty); StringPath = com.DisplayMemberPath; } else { BindingSelected = BindingOperations.GetBinding(com, ComboBox.SelectedItemProperty); } break; } } } } } else { var boundColumn = item as DataGridBoundColumn; if (boundColumn != null) { BindingSelected = boundColumn.Binding as System.Windows.Data.Binding; } } if (BindingSelected != null && BindingSelected.Path != null && !string.IsNullOrWhiteSpace(BindingSelected.Path.Path)) { System.Reflection.PropertyInfo propInfo = null; if (!string.IsNullOrWhiteSpace(StringPath)) { System.Reflection.PropertyInfo propInfo2 = null; if (FilterSelectedItem.Grid.FilterType != null) { propInfo2 = FilterSelectedItem.Grid.FilterType.GetProperty(BindingSelected.Path.Path); } propInfo = propInfo2.PropertyType.GetProperty(StringPath); FilterSelectedItem.GridColumnsName.Add(new ColumnInfo() { ColumnTitle = item.Header.ToString(), ColumnField = BindingSelected.Path.Path + "." + StringPath, ColumnsType = propInfo != null ? propInfo.PropertyType : typeof(string), DataGridColumn = item }); } else { if (FilterSelectedItem.Grid.FilterType != null) { propInfo = FilterSelectedItem.Grid.FilterType.GetProperty(BindingSelected.Path.Path); } string title = ""; if (item.Header is CheckBox) { CheckBox cb = item.Header as CheckBox; title = cb.Content == null ? "全选" : cb.Content.ToString(); } else { title = item.Header.ToString(); } FilterSelectedItem.GridColumnsName.Add(new ColumnInfo() { ColumnTitle = title, ColumnField = BindingSelected.Path.Path, ColumnsType = propInfo != null ? propInfo.PropertyType : typeof(string), DataGridColumn = item }); } } } }
private void ReadColumn(MultiComboBox.MultiComboBox comboBox) { if (comboBox.Columns.Count == 0) { for (int i = 0; i < columns.Count; i++) { comboBox.Columns.Add(columns[i]); } } }