コード例 #1
0
ファイル: HtmlUpdater.cs プロジェクト: xgalv/Cryptool2
        private Inline UpdateElement(HtmlTag aTag)
        {
            Inline retVal = null;

            switch (aTag.Name)
            {
            case "text":
                retVal = new Run(aTag["value"]);

                if (currentState.Bold)
                {
                    retVal = new Bold(retVal);
                }
                if (currentState.Italic)
                {
                    retVal = new Italic(retVal);
                }
                if (currentState.Underline)
                {
                    retVal = new Underline(retVal);
                }
                break;

            case "br":
                retVal = new LineBreak();
                break;
            }


            if (currentState.HyperLink != null && currentState.HyperLink != "")
            {
                Hyperlink link = new Hyperlink(retVal);
                try
                {
                    link.NavigateUri      = new Uri(currentState.HyperLink);
                    link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate);
                }
                catch
                {
                    link.NavigateUri = null;
                }
                retVal = link;
            }

            return(retVal);
        }
コード例 #2
0
ファイル: HtmlUpdater.cs プロジェクト: zvtrung/fileexplorer
        private Inline UpdateElement(HtmlTag aTag)
        {
            Inline retVal = null;

            switch (aTag.Name)
            {
            case "binding":
            case "text":
                if (aTag.Name == "binding")
                {
                    retVal = new Bold(new Run("{Binding}"));
                    if (aTag.Contains("path") && (textBlock.DataContext != null))
                    {
                        object       obj = textBlock.DataContext;
                        PropertyInfo pi  = obj.GetType().GetProperty(aTag["path"]);
                        if (pi != null && pi.CanRead)
                        {
                            retVal = new Run(pi.GetValue(obj, null).ToString());
                        }
                    }
                }
                else
                {
                    retVal = new Run(aTag["value"]);
                }

                if (currentState.SubScript)
                {
                    retVal.SetValue(Typography.VariantsProperty, FontVariants.Subscript);
                }
                if (currentState.SuperScript)
                {
                    retVal.SetValue(Typography.VariantsProperty, FontVariants.Superscript);
                }
                if (currentState.Bold)
                {
                    retVal = new Bold(retVal);
                }
                if (currentState.Italic)
                {
                    retVal = new Italic(retVal);
                }
                if (currentState.Underline)
                {
                    retVal = new Underline(retVal);
                }

                if (currentState.Foreground.HasValue)
                {
                    retVal.Foreground = new SolidColorBrush(currentState.Foreground.Value);
                }

                if (currentState.Font != null)
                {
                    try { retVal.FontFamily = new FontFamily(currentState.Font); }
                    catch { }     //Font name not found...
                }
                if (currentState.FontSize.HasValue)
                {
                    retVal.FontSize = currentState.FontSize.Value;
                }

                break;

            case "br":
                retVal = new LineBreak();
                break;

            default:
                Debug.WriteLine("UpdateElement - " + aTag.Name + " not handled.");
                retVal = new Run();
                //Image img = new Image();
                //BitmapImage bi = new BitmapImage(new Uri(@"c:\temp\1148706365-1.png"));
                //img.Source = bi;
                //retVal = new Figure(new BlockUIContainer(img));
                break;
            }


            if (currentState.HyperLink != null && currentState.HyperLink != "")
            {
                Hyperlink link = new Hyperlink(retVal);
                try
                {
                    link.NavigateUri = new Uri(currentState.HyperLink);
                }
                catch
                {
                    link.NavigateUri = null;
                }
                retVal = link;
            }

            return(retVal);
        }