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 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); }