コード例 #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            HighlightedTextInfo textInfo           = (HighlightedTextInfo)value;
            HightlitedTextConverterParameter param = (HightlitedTextConverterParameter)parameter;

            FormattedString result = new FormattedString();

            if (textInfo.FirstCharIndex == textInfo.Lenght)
            {
                result.Spans.Add(new Span {
                    Text = textInfo.Text
                });
            }
            else
            {
                var firstPart = textInfo.Text.Substring(0, textInfo.FirstCharIndex);
                if (!string.IsNullOrEmpty(firstPart))
                {
                    result.Spans.Add(new Span {
                        Text = firstPart
                    });
                }

                var middlePart = textInfo.Text.Substring(textInfo.FirstCharIndex, textInfo.Lenght);
                if (!string.IsNullOrEmpty(middlePart))
                {
                    result.Spans.Add(new Span {
                        Text = middlePart, ForegroundColor = param.HighlightTextColor, BackgroundColor = param.HighlightBackgroundColor
                    });
                }

                var lastPart = textInfo.Text.Substring(textInfo.FirstCharIndex + textInfo.Lenght);
                if (!string.IsNullOrEmpty(lastPart))
                {
                    result.Spans.Add(new Span {
                        Text = lastPart
                    });
                }
            }

            return(result);
        }
コード例 #2
0
 public ExampleNameSearchResultViewModel(SearchResultType resultType, string controlName, string controlDisplayName, string exampleName, string exampleDisplayName, HighlightedTextInfo highlightedTextInfo)
     : base(resultType, controlName, controlDisplayName, highlightedTextInfo)
 {
     this.ExampleName        = exampleName;
     this.ExampleDisplayName = exampleDisplayName;
 }
 public ControlDescriptionSearchResultViewModel(SearchResultType resultType, string controlName, string controlDisplayName, string description, HighlightedTextInfo highlightedTextInfo)
     : base(resultType, controlName, controlDisplayName, highlightedTextInfo)
 {
     this.Description = description;
 }
 public ExampleDescriptionSearchResultViewModel(SearchResultType resultType, string controlName, string exampleName, string description, HighlightedTextInfo highlightedTextInfo)
     : base(resultType, controlName, exampleName, highlightedTextInfo)
 {
     this.Description = description;
 }