Beispiel #1
0
        private DataGridColumn GetDataGridColumn(GridItem gItem)
        {
            Binding bding = new Binding();

            if (!string.IsNullOrEmpty(gItem.PropertyName))
            {
                bding.Mode = BindingMode.TwoWay;
                bding.Path = new PropertyPath(gItem.PropertyName);
                if (gItem.ReferenceDataInfo != null)
                {
                    IValueConverter converter = CommonFunction.GetIValueConverter(gItem.ReferenceDataInfo.Type);
                    bding.Converter = converter;
                }
                else if (gItem.PropertyName.Contains("MONEY"))
                {
                    IValueConverter converter = new CurrencyConverter();
                    bding.Converter = converter;
                }
                else
                {
                    IValueConverter converter = new CommonConvert(gItem);
                    bding.Converter = converter;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("");
            }

            DataGridColumn dgc = null;

            switch (gItem.CType)
            {
            case ControlType.CheckBox:
                DataGridCheckBoxColumn dgcc = new DataGridCheckBoxColumn();
                dgcc.IsThreeState = false;
                dgcc.Binding      = bding;
                dgc = dgcc;
                break;

            case ControlType.Label:
                if (gItem.ReferenceDataInfo != null)
                {
                    DataGridReferenceColumn dgrc = new DataGridReferenceColumn();
                    dgrc.Binding           = bding;
                    dgrc.DisplayMemberPath = "Text";

                    dgc = dgrc;
                }
                else
                {
                    DataGridTextColumn dgtc = new MyDataGridTextColumn(gItem);
                    dgtc.Binding = bding;
                    dgc          = dgtc;
                }
                break;

            case ControlType.Combobox:

                DataGridComboBoxColumn dgcbc = new DataGridComboBoxColumn();
                if (gItem.ReferenceDataInfo != null)
                {
                    IList <ITextValueItem> list = DataCore.GetRefData(gItem.ReferenceDataInfo.Type);
                    dgcbc.ItemsSource = list;
                }
                dgcbc.DisplayMemberPath = "Text";
                dgcbc.Binding           = bding;

                dgc = dgcbc;
                break;

            case ControlType.TreeViewItem:
                DataGridIconColumn dgtvic = new DataGridIconColumn();
                dgtvic.Binding = bding;
                dgc            = dgtvic;
                break;

            case ControlType.Templete:

                //"<StackPanel Orientation="Horizontal"><smtx:ImageButton x:Name="myDelete" Click="Delete_Click"/></StackPanel>"
                var gridXCs = new XElementString("StackPanel", new XAttributeString("Orientation", "Horizontal"));

                DataGridTemplateColumn dtc = new DataGridTemplateColumn();
                dtc.CellTemplate = DataTemplateHelper.GetDataTemplate(gridXCs);
                dgc = dtc;
                break;
            }

            return(dgc);
        }
Beispiel #2
0
        private DataGridColumn GetDataGridColumn(GridItem gItem)
        {
            Binding bding = new Binding();
            if (!string.IsNullOrEmpty(gItem.PropertyName))
            {
                bding.Mode = BindingMode.TwoWay;
                bding.Path = new PropertyPath(gItem.PropertyName);
                if (gItem.ReferenceDataInfo != null)
                {
                    IValueConverter converter = CommonFunction.GetIValueConverter(gItem.ReferenceDataInfo.Type);
                    bding.Converter = converter;
                }
                else if (gItem.PropertyName.Contains("MONEY"))
                {
                    IValueConverter converter = new CurrencyConverter();
                    bding.Converter = converter;
                }
                else
                {
                    IValueConverter converter = new CommonConvert(gItem);
                    bding.Converter = converter;
                }
                
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("");
            }

            DataGridColumn dgc = null;
            switch (gItem.CType)
            {
                case ControlType.CheckBox :
                    DataGridCheckBoxColumn dgcc = new DataGridCheckBoxColumn();
                    dgcc.IsThreeState = false;
                    dgcc.Binding = bding;
                    dgc = dgcc;
                    break;
                case ControlType.Label :
                    if (gItem.ReferenceDataInfo != null)
                    {
                        DataGridReferenceColumn dgrc = new DataGridReferenceColumn();
                        dgrc.Binding = bding;
                        dgrc.DisplayMemberPath = "Text";
                        
                        dgc = dgrc;

                    }
                    else
                    {
                        DataGridTextColumn dgtc = new MyDataGridTextColumn(gItem);
                        dgtc.Binding = bding;
                        dgc = dgtc;
                    }
                    break;

                case ControlType.Combobox :

                    DataGridComboBoxColumn dgcbc = new DataGridComboBoxColumn();
                    if (gItem.ReferenceDataInfo != null)
                    {
                        IList<ITextValueItem> list = DataCore.GetRefData(gItem.ReferenceDataInfo.Type);
                        dgcbc.ItemsSource = list;
                    }
                    dgcbc.DisplayMemberPath = "Text";
                    dgcbc.Binding = bding;

                    dgc = dgcbc;
                    break;

                case ControlType.TreeViewItem :
                    DataGridIconColumn dgtvic = new DataGridIconColumn();
                    dgtvic.Binding = bding;
                    dgc = dgtvic;
                    break;
                case ControlType.Templete:
                    
                     //"<StackPanel Orientation="Horizontal"><smtx:ImageButton x:Name="myDelete" Click="Delete_Click"/></StackPanel>"
                    var gridXCs = new XElementString("StackPanel",new XAttributeString("Orientation", "Horizontal"));
                  
                    DataGridTemplateColumn dtc = new DataGridTemplateColumn();
                    dtc.CellTemplate = DataTemplateHelper.GetDataTemplate(gridXCs);
                    dgc = dtc;
                    break;
            }

            return dgc;
        }