summaryrefslogtreecommitdiff
path: root/Juick/Classes/ParagraphBindingBehavior.cs
blob: 524f4db12face55cfd7e91beeb241f0d54132e5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;

namespace Juick.Classes
{
    public static class ParagraphBindingBehavior
    {
        public static readonly DependencyProperty AssignedInlinesProperty =
            DependencyProperty.RegisterAttached("AssignedInlines", typeof(IEnumerable<Inline>), typeof(Paragraph), new PropertyMetadata(null, AssignedInlinesCallback));

        static void AssignedInlinesCallback(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            var inlines = ((Paragraph)target).Inlines;
            inlines.Clear();
            var value = e.NewValue as IEnumerable<Inline>;
            if (value != null)
            {
                foreach (var inline in value)
                {
                    inlines.Add(inline);
                }
            }
        }

        public static IEnumerable<Inline> GetAssignedInlines(DependencyObject obj)
        {
            return (IEnumerable<Inline>)obj.GetValue(AssignedInlinesProperty);
        }

        public static void SetAssignedInlines(DependencyObject obj, IEnumerable<Inline> value)
        {
            obj.SetValue(AssignedInlinesProperty, value);
        }
    }
}