protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { DatePicker picker = new DatePicker(); picker.SetBinding(DatePicker.SelectedDateProperty, this.Binding); picker.IsDropDownOpen = true; return picker; }
public DateTimeEditor(WorkFrame frame) : base(frame) { StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Horizontal; time = new TextBox(); time.DataContext = this; time.Width = 64; var timeBinding = new Binding("Value"); timeBinding.Mode = BindingMode.TwoWay; timeBinding.Converter = this; time.SetBinding(TextBox.TextProperty, timeBinding); date = new DatePicker(); date.DataContext = this; var dateBinding = new Binding("Value"); dateBinding.Converter = new DateConvert(time); dateBinding.Mode = BindingMode.TwoWay; date.SetBinding(DatePicker.SelectedDateProperty, dateBinding); Button now = new Button(); now.Content = "当前时间"; now.Click += (s, e) => Value = DateTime.Now; panel.Children.Add(date); panel.Children.Add(time); panel.Children.Add(now); Content = panel; }
public FrameworkElement CreateView(PropertyInfo property) { var inputControl = new DatePicker(); var binding = new Binding(property.Name); binding.Mode = BindingMode.TwoWay; inputControl.SetBinding(DatePicker.SelectedDateProperty, binding); return inputControl; }
public override void OnApplyTemplate() { base.OnApplyTemplate(); DatePicker = (DatePicker)GetTemplateChild("PART_DatePicker"); DatePicker.SetBinding(DatePicker.SelectedDateProperty, new Binding { Source = this, Path = new PropertyPath(CurrentValueProperty), Mode = BindingMode.TwoWay }); DatePicker.SelectedDateChanged += DatePicker_SelectedDateChanged; }
protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem) { var element = new DatePicker { Style = Application.Current.Resources["DatePickerStyle"] as Style }; element.SetBinding(DatePicker.SelectedDateProperty, Binding); return element; }
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { DatePicker picker = new DatePicker(); picker.MinHeight = 16; picker.Padding = new Thickness(0); picker.BorderThickness = new Thickness(0); picker.SetBinding(DatePicker.SelectedDateProperty, Binding); picker.IsDropDownOpen = true; return picker; }
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { var dp = new DatePicker {VerticalAlignment = VerticalAlignment.Stretch}; if (DateFormat != null) { IValueConverter dtc = new DateTimeConverter(); Binding.Converter = dtc; Binding.ConverterParameter = DateFormat; } dp.SetBinding(DatePicker.SelectedDateProperty, Binding); return dp; }
public override FrameworkElement CreateControl(FormItemContext context) { DatePicker picker = new DatePicker(); var binding = new Binding(context.PropertyInfo.Name) { Mode = BindingMode.TwoWay, }; binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo)); picker.SetBinding(DatePicker.SelectedDateProperty, binding); CustomValidation.SetValidationProperty(picker, DatePicker.SelectedDateProperty); StyleHelper.ApplyStyle(picker, FormControlConstrants.EDIT_DATE_STYLE); return picker; }
public DateEditor(WorkFrame frame) : base(frame) { StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Horizontal; DatePicker date = new DatePicker(); date.Width = 120; date.DataContext = this; var binding = new Binding("Value"); binding.Mode = BindingMode.TwoWay; date.SetBinding(DatePicker.SelectedDateProperty, binding); panel.Children.Add(date); Content = panel; }
private static ModelPropertyUiInfo CreateDateField(Grid grid, DisplayPropertyInfo property, String bindingPath, Style style, int row, int column) { Label labelElement = CreateLabel(property, row, column); DatePicker control = new DatePicker { Name = "datePicker" + property.PropertyName }; if (style != null) { control.Style = style; } Binding binding = ModelUiCreatorHelper.CreateBinding(property, bindingPath); control.SetBinding(DatePicker.SelectedDateProperty, binding); if (property.IsReadOnly) { control.IsEnabled = false; } Grid.SetRow(control, row); Grid.SetColumn(control, checked(column + 1)); grid.Children.Add(labelElement); grid.Children.Add(control); // return ModelPropertyUiInfo elememtsInfo = new ModelPropertyUiInfo(property); elememtsInfo.Label = labelElement; elememtsInfo.Content = control; return elememtsInfo; }
private void Init() { var detail = this; foreach (var propertyInfo in TypeObj.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)) { detail.Children.Add(new TextBlock { Text = SeparateCapitalWords(propertyInfo.Name) }); FrameworkElement element; var binding = new Binding(propertyInfo.Name); if (propertyInfo.CanWrite) { binding.Mode = BindingMode.TwoWay; if (typeof(DateTime).IsAssignableFrom(propertyInfo.PropertyType)) { var dtp = new DatePicker(); dtp.SetBinding(DatePicker.SelectedDateProperty, binding); element = new CoverControl { Control = dtp, Name = propertyInfo.Name }; } else if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType)) { var cb = new ComboBox(); cb.SetBinding(Selector.SelectedItemProperty, binding); var propertyInfo1 = propertyInfo; Utilities.FillEnums(cb, propertyInfo1.PropertyType); element = new CoverControl { Control = cb, Name = propertyInfo.Name }; } else if (typeof(Persistent).IsAssignableFrom(propertyInfo.PropertyType)) { var cb = new ComboBox(); cb.SetBinding(Selector.SelectedItemProperty, binding); var propertyInfo1 = propertyInfo; dropdowns[cb] = propertyInfo1.PropertyType; element = new CoverControl { Control = cb, Name = propertyInfo.Name }; } else { var tb = new TextBox(); tb.SetBinding(TextBox.TextProperty, binding); element = new CoverControl { Control = tb, Name = propertyInfo.Name }; } } else { binding.Mode = BindingMode.OneWay; var tb = new TextBlock(); tb.SetBinding(TextBlock.TextProperty, binding); element = tb; } detail.Children.Add(element); } var grid = new Grid { Margin = new Thickness(0, 50, 0, 0) }; grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); var b = new Button { Content = "Delete" }; b.Click += DeleteOnClick; b.SetValue(Grid.ColumnProperty, 2); grid.Children.Add(b); detail.Children.Add(grid); }
private FrameworkElement CreateControl(DataFieldItem dfItem) { ControlType cType = dfItem.CType; Binding binding = new Binding(); binding.Path = new PropertyPath(dfItem.PropertyName); binding.Mode = BindingMode.TwoWay; binding.Converter = new CommonConvert(dfItem); FrameworkElement c = null; switch (cType) { case ControlType.Label: TextBlock tbx = new TextBlock(); if (dfItem.ReferenceDataInfo != null) { binding.Path = new PropertyPath(dfItem.ReferenceDataInfo.ReferencedMember + ".Text"); } tbx.SetBinding(TextBlock.TextProperty, binding); c = tbx; break; case ControlType.TextBox: TextBox tb = new TextBox(); tb.SetBinding(TextBox.TextProperty, binding); tb.IsReadOnly = (IsReadOnly || dfItem.IsReadOnly); tb.MaxLength = dfItem.MaxLength; if ( dfItem.DataType.ToLower() == "decimal" || dfItem.DataType.ToLower() == "datetime") { tb.TextAlignment = TextAlignment.Right; } c = tb; break; case ControlType.Combobox: ComboBox cbb = new ComboBox(); if (dfItem.ReferenceDataInfo != null) { cbb.ItemsSource = this.GetItemSource(dfItem.ReferenceDataInfo.Type); cbb.DisplayMemberPath = "Text"; binding.Path = new PropertyPath(dfItem.ReferenceDataInfo.ReferencedMember); } cbb.SetBinding(ComboBox.SelectedItemProperty, binding); cbb.IsEnabled = !(IsReadOnly || dfItem.IsReadOnly); c = cbb; break; case ControlType.LookUp: FBLookUp lookUp = new FBLookUp(); lookUp.OperationType = this.OperationType; lookUp.DisplayMemberPath = dfItem.PropertyName; if (dfItem.ReferenceDataInfo != null) { lookUp.DisplayMemberPath = dfItem.ReferenceDataInfo.ReferencedMember + ".Text"; if (!string.IsNullOrEmpty(dfItem.ReferenceDataInfo.TextPath)) { lookUp.DisplayMemberPath = dfItem.ReferenceDataInfo.TextPath; } lookUp.LookUpType = dfItem.ReferenceDataInfo.Type; binding.Path = new PropertyPath(dfItem.ReferenceDataInfo.ReferencedMember); } lookUp.SetBinding(LookUp.SelectItemProperty, binding); lookUp.ReferencedDataInfo = dfItem.ReferenceDataInfo; lookUp.Parameters = dfItem.ReferenceDataInfo.Parameters; lookUp.IsReadOnly = (IsReadOnly || dfItem.IsReadOnly); c = lookUp; break; case ControlType.Remark: TextBox tbRemark = new TextBox(); tbRemark.AcceptsReturn = true; tbRemark.TextWrapping = TextWrapping.Wrap; //tbRemark.Height = 66; //tbRemark.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; //tbRemark.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; tbRemark.SetBinding(TextBox.TextProperty, binding); c = tbRemark; tbRemark.IsReadOnly = (IsReadOnly || dfItem.IsReadOnly); tbRemark.MaxLength = dfItem.MaxLength; break; case ControlType.DatePicker: DatePicker datePicker = new DatePicker(); datePicker.SelectedDateFormat = DatePickerFormat.Short; datePicker.SetBinding(DatePicker.SelectedDateProperty, binding); c = datePicker; datePicker.IsEnabled = !(IsReadOnly || dfItem.IsReadOnly); break; case ControlType.DateTimePicker: DateTimePicker dateTimePicker = new DateTimePicker(); dateTimePicker.SetBinding(DateTimePicker.ValueProperty, binding); c = dateTimePicker; dateTimePicker.IsEnabled = !(IsReadOnly || dfItem.IsReadOnly); break; // Add By LVCHAO 2011.01.30 14:46 case ControlType.HyperlinkButton: HyperlinkButton hb = new HyperlinkButton(); if (dfItem.ReferenceDataInfo != null) { binding.Path = new PropertyPath(dfItem.ReferenceDataInfo.ReferencedMember + ".Text"); } hb.Click += (o, e) => { var sourceOjb = hb.DataContext.GetObjValue(dfItem.ReferenceDataInfo.ReferencedMember + ".Value"); CommonFunction.ShowExtendForm(sourceOjb); }; hb.SetBinding(HyperlinkButton.ContentProperty, binding); c = hb; break; } return c; }
private Control GetControlByType(RdlType.ReportParameterType parameter, Binding paramValueBind) { Control paramControl = new TextBox(); BindingExpressionBase expr = null; if (parameter.HasValidValues) { paramControl = new ComboBox() { ItemsSource = viewModel.ReportType.GetReportParameterValidValues(parameter.Name), SelectedValuePath = "Value", DisplayMemberPath = "Key" }; expr = paramControl.SetBinding(ComboBox.SelectedValueProperty, paramValueBind); } else { switch (parameter.DataType) { case RdlType.ReportParameterType.DataTypeEnum.DateTime: paramControl = new DatePicker(); expr = paramControl.SetBinding(DatePicker.SelectedDateProperty, paramValueBind); break; case RdlType.ReportParameterType.DataTypeEnum.Boolean: paramControl = new CheckBox(); expr = paramControl.SetBinding(CheckBox.IsCheckedProperty, paramValueBind); break; case RdlType.ReportParameterType.DataTypeEnum.Integer: paramControl = new IntegerUpDown(); expr = paramControl.SetBinding(IntegerUpDown.ValueProperty, paramValueBind); break; case RdlType.ReportParameterType.DataTypeEnum.Float: paramControl = new DecimalUpDown(); expr = paramControl.SetBinding(DecimalUpDown.ValueProperty, paramValueBind); break; default: expr = paramControl.SetBinding(TextBox.TextProperty, paramValueBind); break; } } viewModel.ClearParameters += (sender, args) => expr.UpdateTarget(); return paramControl; }
/// <summary> /// Creates the date time control. /// </summary> /// <param name="property">The property.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateDateTimeControl(PropertyItem property) { var c = new DatePicker(); c.SetBinding(DatePicker.SelectedDateProperty, property.CreateBinding()); return c; }
public static Binding SetDatePickerBinding (DataRowView AktuellView, DatePicker ControlToFill, String DataColumnName) { Binding DateBinding = new Binding (DataColumnName); DateBinding.Source = AktuellView; ControlToFill.SetBinding (DatePicker.SelectedDateProperty, DateBinding); return DateBinding; }
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { DatePicker dp = new DatePicker(); dp.SetBinding(DatePicker.SelectedDateProperty, this.Binding); return dp; }