A
A
Artem2014-09-04 21:38:23
Windows phone
Artem, 2014-09-04 21:38:23

How to work with RichTextBox inside LongListSelector?

I use RichTextBox in LongListSelector like this:

<phone:LongListSelector Name="myLLS">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Name}" />
                <TextBlock Text="{Binding Surname}" />
                <RichTextBox IsReadOnly="True" />
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

C# code:
ObservableCollection<ListItem> listItems = new ObservableCollection<ListItem>();

public MainPage()
    {
        InitializeComponent();

        myLLS.ItemsSource = listItems;

        listItems.Add(new ListItem("John", "Smith", "Some big and formatted text 1"));
        listItems.Add(new ListItem("Bill", "Dixon", "Some big and formatted text 2"));
        listItems.Add(new ListItem("Ralph", "Watson", "Some big and formatted text 3"));
    }

public class ListItem
    {
        private string _name;
        private string _surname;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string Surname
        {
            get { return _surname; }
            set { _surname = value; }
        }

        public ListItem(string name, string surname, string description)
        {
            this.Name = name;
            this.Surname = surname;
            // How to set content to my RichTextBox here?
        }
    }

With the use of TextBlock no problem, the text is normally assigned. But I need to assign text and RichTextBox. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
std, 2015-03-19
@ std

Through a self-written attached-property. Depending on the requirements, this can be a property with the string or Block types (a collection of Blocks). In the property change handler, the contents of RichTextBox.Blocks are filled with Blocks formed from the attached property.
And further in XAML:

<RichTextBox local:RichTextBinding.Source="{Binding Description}" ... />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question