Esempio n. 1
0
        private void GenerateColumns(DataGrid dataGrid, SheetInfo sheetInfo)
        {
            dataGrid.Columns.Clear();
            int i = 0;

            #region Dynamic Columns

            foreach (var m_Column in sheetInfo.Columns)
            {
                if (m_Column.Index > 0)
                {
                    string m_FieldName           = CustomEntity.GetPropertyName(i);
                    string m_BackgroundFieldName = CustomEntity.GetBackgroundFieldName(i);

                    //Use FColumn -> CellTemplate
                    DataGridTemplateColumn m_TemplateColumn = new DataGridTemplateColumn()
                    {
                        Header     = m_Column.Header,
                        IsReadOnly = false,
                    };
                    m_TemplateColumn.CellTemplate = GetDataTemplate(m_FieldName, m_BackgroundFieldName);

                    dataGrid.Columns.Add(m_TemplateColumn);
                    i++;
                }
            }

            #endregion
        }
Esempio n. 2
0
        private DataTemplate BuildDataTemplate(int index, FieldInfo fieldInfo)
        {
            DataTemplate            template  = new DataTemplate();
            FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));
            FrameworkElementFactory border    = new FrameworkElementFactory(typeof(Border));

            border.SetValue(Border.BorderThicknessProperty, new Thickness(2.0));
            border.AppendChild(textBlock);
            template.VisualTree = border;

            string sValuePath = CustomEntity.GetPropertyName(index);

            if (FieldInfo.HasFunctionField(fieldInfo))
            {
                sValuePath = CustomEntity.GetFuncValueName(index);
            }
            textBlock.SetBinding(TextBlock.TextProperty, new Binding(sValuePath));
            textBlock.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
            textBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Stretch);

            //Background color
            Binding bdColor = new Binding(CustomEntity.GetPropertyPath_ErrorBackground(index))
            {
                //RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(DataRow) },
                Mode = BindingMode.OneWay
            };

            border.SetBinding(Border.BorderBrushProperty, bdColor);

            //Tooltip
            Binding bdTooltip = new Binding(CustomEntity.GetPropertyPath_ErrorTooltip(index))
            {
                //RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.FindAncestor, AncestorType = typeof(DataRow) },
                Mode = BindingMode.OneWay
            };

            textBlock.SetBinding(TextBlock.ToolTipProperty, bdTooltip);

            return(template);
        }