Esempio n. 1
0
        /// <summary>
        /// Data Field call back when a field has been changed
        /// </summary>
        /// <param name="d">Dependency object to be set</param>
        /// <param name="e">Event that happens in a dependency object</param>
        private static void OnDataFieldExChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            object          currentSource    = d.GetValue(DataSourceDependencyProperty);
            string          currentDataField = (string)d.GetValue(DataFieldDependencyProperty);
            ComponentFiller filler           = new ComponentFiller();

            if (currentSource != null)
            {
                if (!string.IsNullOrEmpty(currentDataField))
                {
                    if (currentSource is DataTable)
                    {
                        DataTable itemSource  = (DataTable)currentSource;
                        string    valueToFill = filler.FetchDataFieldValue(itemSource, currentDataField);
                        if (d is TextBox)
                        {
                            TextBox box = (TextBox)d;
                            box.Text = valueToFill;
                        }
                        if (d is TextBlock)
                        {
                            TextBlock block = (TextBlock)d;
                            block.Text = valueToFill;
                        }
                        if (d is Image)
                        {
                            object objectValueToFill = filler.FetchDataFieldObject(itemSource, currentDataField);
                            Image  currentImage      = (Image)d;
                            currentImage.Source = new BitmapImage(new Uri((string)objectValueToFill, UriKind.Relative));
                        }
                    }
                    else
                    {
                        var valueObject = filler.FetchDataFieldFromObject(currentSource, currentDataField);
                        if (d is TextBox)
                        {
                            TextBox box = (TextBox)d;
                            box.Text = valueObject as string;
                        }
                        if (d is TextBlock)
                        {
                            TextBlock block = (TextBlock)d;
                            block.Text = valueObject as string;
                        }
                        if (d is Image)
                        {
                            Image currentImage = (Image)d;
                            currentImage.Source = new BitmapImage(new Uri((string)valueObject, UriKind.Relative));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///  This field send us a data field in case of a data source.
        /// </summary>
        /// <param name="d">Dependency object</param>
        /// <param name="e">Data Source</param>
        private static void OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            object          currentObject = d.GetValue(DataSourceDependencyProperty);
            string          dataField     = (string)d.GetValue(DataFieldDependencyProperty);
            ComponentFiller filler        = new ComponentFiller();

            if (currentObject is DataTable)
            {
                DataTable table = (DataTable)currentObject;

                if (d is Image)
                {
                    object current      = filler.FetchDataFieldObject(table, dataField);
                    Image  currentImage = (Image)d;
                    byte[] value        = current as byte[];
                    if (value != null)
                    {
                        filler.FillImageSource(value, ref currentImage);
                    }
                }
                else
                {
                    string value = filler.FetchDataFieldValue(table, dataField);
                    if (d is TextBlock)
                    {
                        TextBlock block = (TextBlock)d;
                        block.Text = value;
                    }
                    if (d is TextBox)
                    {
                        TextBox box = (TextBox)d;
                        box.Text = value;
                    }
                }
            }
            else
            {
                // it is an object and we look for the property specified in the datafield.
                Type         t                 = currentObject.GetType();
                PropertyInfo propInfo          = t.GetProperty(dataField);
                object       currentFieldValue = filler.FetchDataFieldFromObject(currentObject, dataField);
                if (currentFieldValue != null)
                {
                    // currentFieldValue is not null.
                    if (d is Image)
                    {
                        Image  currentImage = (Image)d;
                        byte[] value        = currentFieldValue as byte[];
                        if (value != null)
                        {
                            filler.FillImageSource(value, ref currentImage);
                        }
                        //  d = currentImage;
                    }
                    else
                    {
                        string value = currentFieldValue as string;
                        if (d is TextBlock)
                        {
                            TextBlock block = (TextBlock)d;
                            block.Text = value;
                        }
                        if (d is TextBox)
                        {
                            TextBox box = (TextBox)d;
                            box.Text = value;
                        }
                    }
                }
            }
        }