Exemple #1
0
        private ShowHtmlResDialog(Window parent, string title, string content)
            : base()
        {
            InitializeComponent();

            Icon = Application.Current.MainWindow.Icon;

            if (parent == null)
            {
                parent = Application.Current.MainWindow;
            }
            Owner = parent;

            if (!string.IsNullOrEmpty(title))
            {
                Title = title;
            }

            // Replace image tags with embedded base64
            Dictionary <string, string> images = new Dictionary <string, string>();
            int   offset = 0;
            Match match  = _regex.Match(content, offset);

            while (match.Success)
            {
                string imgfile = match.Groups["file"].Value;
                string base64;
                if (!images.ContainsKey(imgfile))
                {
                    string imgpath = Path.Combine(Settings.RESOURCE_PATH, imgfile);
                    string ext     = Path.GetExtension(imgfile).Substring(1).ToLower();
                    base64 = "data:image/" + ext + ";base64," + CoreLib.ImageHandler.Image2Base64(imgpath);
                }
                else
                {
                    base64 = images[imgfile];
                }

                string to_replace = match.Value;
                content = content.Replace(to_replace, base64);

                int match_pos = match.Index;
                offset = match_pos + base64.Length;

                match = _regex.Match(content, offset);
            }

            WebCtrl.NavigateToString(content);
        }
Exemple #2
0
        private ShowHtmlResDialog(Window parent, string title, string content, string[] extra = null)
            : base()
        {
            InitializeComponent();

            Icon = Application.Current.MainWindow.Icon;

            if (parent == null && Application.Current.MainWindow.IsLoaded)
            {
                parent = Application.Current.MainWindow;
            }
            if (parent != null)
            {
                Owner = parent;
            }

            if (Config.Root.HasSection("dialogs") && Config.Root.dialogs.HasSection("html_res"))
            {
                dynamic section = Config.Root.dialogs.html_res;
                Left   = section.pos_x;
                Top    = section.pos_y;
                Width  = section.size_x;
                Height = section.size_y;
            }
            else
            {
                Width  = 750;
                Height = 500;
                WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            if (!string.IsNullOrEmpty(title))
            {
                Title = title;
            }

            if (extra != null && extra.Length >= 2)
            {
                ExtraBtn.Content    = extra[0];
                ExtraBtn.Visibility = Visibility.Visible;
                CloseBtn.Content    = extra[1];
                if (extra.Length == 3)
                {
                    Hint.Content    = extra[2];
                    Hint.Visibility = Visibility.Visible;
                }
            }

            // Replace image tags with embedded base64
            Dictionary <string, string> images = new Dictionary <string, string>();
            int   offset = 0;
            Match match  = _regex.Match(content, offset);

            while (match.Success)
            {
                string imgfile = match.Groups["file"].Value;
                string base64;
                if (!images.ContainsKey(imgfile))
                {
                    BitmapSource img = new BitmapImage(Helpers.GetResourceUri(imgfile));
                    base64 = "data:image/png;base64," + ImageHandler.Image2Base64(img);
                    images.Add(imgfile, base64);
                }
                else
                {
                    base64 = images[imgfile];
                }

                string to_replace = match.Value;
                content = content.Replace(to_replace, base64);

                int match_pos = match.Index;
                offset = match_pos + base64.Length;

                match = _regex.Match(content, offset);
            }

            WebCtrl.NavigateToString(content);
        }