Beispiel #1
0
        public RichTextPropertyValue ConvertStringToRichText(string value)
        {
            var xmlElement = XElement.Parse("<rich>" + value + "</rich>");

            var richSpan = new RichSpan();

            SetSerializer.DeserializeRichCardProperty(richSpan, xmlElement, ViewModelLocator.GameLoader.Game);


            return(new RichTextPropertyValue()
            {
                Value = richSpan
            });
        }
Beispiel #2
0
        public AltItemModel() //for adding new items
        {
            _altCard            = new CardPropertySet();
            _altCard.Type       = Guid.NewGuid().ToString();
            CardSize            = ViewModelLocator.SizeTabViewModel.Items.First(x => x.Default);
            _altCard.Properties = new Dictionary <PropertyDef, object>();

            var nameProp = new PropertyDef()
            {
                Hidden      = false,
                Name        = "Name",
                Type        = PropertyType.String,
                TextKind    = PropertyTextKind.FreeText,
                IgnoreText  = false,
                IsUndefined = false
            };

            if (nameProp.Type is PropertyType.RichText)
            {
                var span = new RichSpan();
                span.Items.Add(new RichText()
                {
                    Text = "CardName"
                });
                var namePropValue = new RichTextPropertyValue();
                namePropValue.Value = span;
                _altCard.Properties.Add(nameProp, namePropValue);
            }
            else
            {
                _altCard.Properties.Add(nameProp, "CardName");
            }
            AltTypeVisibility = Visibility.Collapsed;

            Properties = new ObservableCollection <CardPropertyItemModel>();
        }
Beispiel #3
0
        private static void InternalProcess(Span span, RichSpan node)
        {
            foreach (RichSpan child in node.Items)
            {
                if (child is RichText text)
                {
                    span.Inlines.Add(new Run(text.Text.ToString()));
                }
                else if (child is RichSpan element)
                {
                    switch (element.Type)
                    {
                    case RichSpanType.Bold:
                    {
                        Span boldSpan = new Span();
                        InternalProcess(boldSpan, element);
                        Bold bold = new Bold(boldSpan);
                        span.Inlines.Add(bold);
                        break;
                    }

                    case RichSpanType.Italic:
                    {
                        Span italicSpan = new Span();
                        InternalProcess(italicSpan, element);
                        Italic italic = new Italic(italicSpan);
                        span.Inlines.Add(italic);
                        break;
                    }

                    case RichSpanType.Underline:
                    {
                        Span underlineSpan = new Span();
                        InternalProcess(underlineSpan, element);
                        Underline underline = new Underline(underlineSpan);
                        span.Inlines.Add(underline);
                        break;
                    }

                    case RichSpanType.Color:
                    {
                        Span colorSpan = new Span();
                        InternalProcess(colorSpan, element);
                        colorSpan.Foreground = new BrushConverter().ConvertFromString((element as RichColor).Attribute) as SolidColorBrush;
                        span.Inlines.Add(colorSpan);
                        break;
                    }

                    case RichSpanType.Symbol:
                    {
                        Symbol symbol = (element as RichSymbol).Attribute;

                        var image = new Image
                        {
                            Margin  = new Thickness(0, 0, 0, -2),
                            Height  = span.FontSize + 2,
                            Stretch = Stretch.Uniform,
                            Source  = new BitmapImage(new Uri(symbol.Source)),
                            ToolTip = symbol.Name
                        };

                        var symbolSpan = new InlineUIContainer();
                        symbolSpan.Child = image;

                        span.Inlines.Add(symbolSpan);
                        break;
                    }
                    }
                }
            }
        }