Example #1
0
        public void Deserialize(Control element, DataStore data)
        {
            if (isImage)
            {
                designSave.ToControl(data, element);
                element.Tag = designSave.Serialize();

                if(ScaleQuality != BitmapScalingMode.Linear && ScaleQuality != BitmapScalingMode.Unspecified)
                RenderOptions.SetBitmapScalingMode(element, ScaleQuality);
            }
            else
            {
                if(!string.IsNullOrWhiteSpace(BrushS))
                element.Background = (Brush)SaveEditor.XMLDeserialize(BrushS);
            }
            
        }
Example #2
0
        }//ToSerializableCanvas

        public static void ExtractHiddenData(DataStore data, Canvas canvas, int pos)
        {
            if ((int)data.BitmapScalingMode != 1)
            {
                RenderOptions.SetBitmapScalingMode(canvas, data.BitmapScalingMode);
            }

            if (data.pages[pos].IsImageBrush)
            {
                canvas.Background = new ImageBrush(data.archive.GetImage(data.pages[pos].ImageBrush.Path));
                ((ImageBrush)canvas.Background).Stretch = data.pages[pos].ImageBrush.stretch;
            }
            else if (data.pages[pos].CustomBrush && !String.IsNullOrWhiteSpace(data.pages[pos].canvasbrush))
            {
                canvas.Background = (Brush)SaveEditor.XMLDeserialize(data.pages[pos].canvasbrush);
            }
            else
            {
                if (data.IsImageBrush)
                {
                    canvas.Background = new ImageBrush(data.archive.GetImage(data.ImageBrush.Path));
                    ((ImageBrush)canvas.Background).Stretch = data.ImageBrush.stretch;
                }
                else if (!String.IsNullOrEmpty(data.AllBackground))
                {
                    canvas.Background = (Brush)SaveEditor.XMLDeserialize(data.AllBackground);
                }
                else
                {
                    canvas.Background = new SolidColorBrush(Colors.White);
                }
            }

            foreach (FrameworkElement frw in canvas.Children)
            {
                if (frw is Image)
                {
                    Image img = (Image)frw;


                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                        img.Source = new BitmapImage(new Uri("pack://application:,,,/Good Teacher;Component/Resources/Controls/image.png"));
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(img.Tag.ToString());
                        designSave.ToImage(data, img);
                    }
                }
                else if (frw is Shape)
                {
                    Shape shape = (Shape)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(shape.Tag.ToString());
                        designSave.ToShape(data, shape);
                    }
                }
                else if (frw is Label || frw is CheckBox || frw is RadioButton)
                {
                    Control control = (Control)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(control.Tag.ToString());
                        designSave.ToControlWithForeground(data, control);
                    }


                    if (control.FontFamily.BaseUri != null && control.FontFamily.Source != null)
                    {
                        Debug.WriteLine("Ffontfamilysource: " + control.FontFamily.Source);

                        string fontfamilyloc  = "";
                        string fontfamilyfile = "";

                        if (control.FontFamily.Source.Length >= 5)
                        {
                            fontfamilyloc  = control.FontFamily.Source.Substring(0, 3);
                            fontfamilyfile = control.FontFamily.Source.Substring(0, 5);
                        }

                        if (!string.IsNullOrWhiteSpace(control.FontFamily.Source) && (fontfamilyloc == "./#" || fontfamilyfile == "file:"))
                        {
                            //Debug.WriteLine("-------------------\nBU: " + control.FontFamily.BaseUri + "\nFF: " + control.FontFamily + "\nAP: " + control.FontFamily.BaseUri.AbsolutePath + "\nAU: " + control.FontFamily.BaseUri.AbsoluteUri + "\nH: " + control.FontFamily.BaseUri.Host + "\nS: " + control.FontFamily.Source + "\n********\n");

                            FontFamily fontFamily;
                            if (FontWorker.GetFontFamily(control.FontFamily, out fontFamily))
                            {
                                control.FontFamily = fontFamily;
                            }
                        }
                    }
                }
                else if (frw is MediaPlayer_Control)
                {
                    //Nothing
                }
                else if (frw is Control)
                {
                    Control control = (Control)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(control.Tag.ToString());
                        designSave.ToControl(data, control);
                    }

                    if (control.FontFamily.BaseUri != null)
                    {
                        //Debug.WriteLine(""+ control.FontFamily.BaseUri+ "  "+ control.FontFamily+"    AP: "+control.FontFamily.BaseUri.AbsolutePath+"   AU: "+control.FontFamily.BaseUri.AbsoluteUri+"   H: "+control.FontFamily.BaseUri.Host+ "   S: "+control.FontFamily.Source);

                        FontFamily fontFamily;
                        if (FontWorker.GetFontFamily(control.FontFamily, out fontFamily))
                        {
                            control.FontFamily = fontFamily;
                        }
                    }
                }
            }

            DeserializeCustomControls(data, canvas, pos);
        }