示例#1
0
        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            if (FieldInfo == null)
            {
                return(base.GenerateElement(cell, dataItem));
            }

            FieldType fieldType       = FieldInfo.FieldType;
            string    actualFieldName = null;

            if (fieldType == FieldType.Attachment)
            {
                return(new TextBlock());
                //AttachmentFieldValue attachmentFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as AttachmentFieldValue;
                //if (attachmentFieldValue != null && attachmentFieldValue.AttachmentsProvider != null)
                //{
                //return base.GenerateElement(cell, dataItem);
                //StackPanel attachmentsStackPanel = new StackPanel();

                //if (attachmentFieldValue.AttachmentsProvider.HasAlreadyRetrievedAttachments())
                //{
                //    MultipleAttachmentsInfo attachments = attachmentFieldValue.AttachmentsProvider.GetAttachments();
                //    buildAttachmentsPanel(attachmentsStackPanel, attachments);
                //}
                //else
                //{
                //    HyperlinkButton attachmentsAnchor = createHyperlinkButton(null, "Retrieve");
                //    attachmentsAnchor.DataContext = attachmentFieldValue;
                //    attachmentsStackPanel.Children.Add(attachmentsAnchor);
                //    StackPanel attachmentsContainer = new StackPanel();
                //    attachmentsAnchor.Tag = attachmentsStackPanel;
                //    attachmentsAnchor.Click += new RoutedEventHandler(attachmentsAnchor_Click);
                //    attachmentsStackPanel.Children.Add(attachmentsContainer);
                //}

                //return attachmentsStackPanel;
                //}
            }
            else if (fieldType == FieldType.Entity)
            {
                EntityFieldValue entityFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as EntityFieldValue;
                if (entityFieldValue != null)
                {
                    return(getHyperlinkButton(string.Format("{0}.LinkUrl", actualFieldName)));
                }
            }
            else if (fieldType == FieldType.Hyperlink)
            {
                HyperlinkFieldValue hyperLinkFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as HyperlinkFieldValue;
                if (hyperLinkFieldValue != null)
                {
                    //TextBlock tblock = new TextBlock();
                    //tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.DisplayText", actualFieldName)));
                    //HyperlinkButton hyperlinkButton = new HyperlinkButton();
                    //hyperlinkButton.Click += new RoutedEventHandler(hyperlinkButton_Click);
                    //hyperlinkButton.Content = tblock;
                    //return hyperlinkButton;
                    //return tblock;

                    return(getHyperlinkButton(string.Format("{0}.LinkUrl", actualFieldName)));

                    //TextBlock tblock = new TextBlock();
                    //tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.LinkUrl", actualFieldName)));
                    //return tblock;
                }
            }
            else if (fieldType == FieldType.Image)
            {
                HyperlinkImageFieldValue hyperLinkImageFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as HyperlinkImageFieldValue;
                if (hyperLinkImageFieldValue != null)
                {
                    return(getHyperlinkButton(string.Format("{0}.ImageUrl", actualFieldName)));
                }
            }
            else if (fieldType == FieldType.Currency)
            {
                CurrencyFieldValue currencyFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as CurrencyFieldValue;
                if (currencyFieldValue != null)
                {
                    TextBlock tblock = new TextBlock();
                    tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.FormattedValue", actualFieldName)));
                    return(tblock);
                }
            }
            else if (fieldType == FieldType.DateTime)
            {
                DateTimeFieldValue dateTimeFieldValue = getPropertyValue(FieldInfo.Name, dataItem, out actualFieldName) as DateTimeFieldValue;
                if (dateTimeFieldValue != null)
                {
                    TextBlock tblock = new TextBlock();
                    tblock.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(string.Format("{0}.FormattedValue", actualFieldName)));
                    return(tblock);
                }
            }

            return(base.GenerateElement(cell, dataItem));
        }
示例#2
0
        private static void getMinAndMaxForGraphicsLayer(GraphicsLayer graphicsLayer, FieldInfo attributeField, out double min, out double max)
        {
            min = double.NaN;
            max = double.NaN;
            if (graphicsLayer != null && attributeField != null && !string.IsNullOrEmpty(attributeField.Name))
            {
                foreach (Graphic g in graphicsLayer.Graphics)
                {
                    object o;
                    if (g.Attributes.TryGetValue(attributeField.Name, out o))
                    {
                        if (o == null)
                        {
                            continue;
                        }
                        double            value;
                        NumericFieldValue numericFieldValue = o as NumericFieldValue;
                        if (numericFieldValue != null)
                        {
                            o = numericFieldValue.Value;
                        }
                        else
                        {
                            CurrencyFieldValue currencyFieldValue = o as CurrencyFieldValue;
                            if (currencyFieldValue != null)
                            {
                                o = currencyFieldValue.Value;
                            }
                        }

                        if (double.TryParse(
                                string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", o),
                                System.Globalization.NumberStyles.Any,
                                System.Globalization.CultureInfo.InvariantCulture, out value))
                        {
                            if (double.IsNaN(min)) // first value
                            {
                                min = value;
                            }
                            else
                            {
                                min = Math.Min(min, value);
                            }

                            if (double.IsNaN(max)) // first value
                            {
                                max = value;
                            }
                            else
                            {
                                max = Math.Max(max, value);
                            }
                        }
                    }
                }
            }
            if (double.IsNaN(min))
            {
                min = 0d;
            }
            if (double.IsNaN(max))
            {
                max = 0d;
            }
        }