summaryrefslogtreecommitdiff
path: root/Juick/Classes/DeferredLoadListBoxItem.cs
blob: 97bfc18c85eb67c6cdcf2432f00d4b23900b9d9f (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
37
38
39
40
41
42
43
44
45
// Copyright (C) Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the Microsoft Public License
// (Ms-PL, http://opensource.org/licenses/ms-pl.html).

using System.Windows;
using System.Windows.Controls;

namespace Juick.Classes
{
    /// <summary>
    /// Implements a subclass of ListBoxItem that is used in conjunction with
    /// the DeferredLoadListBox to defer the loading of off-screen items.
    /// </summary>
    public class DeferredLoadListBoxItem : ListBoxItem
    {
        private object _maskedContent;
        private DataTemplate _maskedContentTemplate;

        internal bool Masked { get; set; }

        internal void MaskContent()
        {
            if (!Masked)
            {
                _maskedContent = Content;
                _maskedContentTemplate = ContentTemplate;
                Content = null;
                ContentTemplate = null;
                Masked = true;
            }
        }

        internal void UnmaskContent()
        {
            if (Masked)
            {
                ContentTemplate = _maskedContentTemplate;
                Content = _maskedContent;
                _maskedContentTemplate = null;
                _maskedContent = null;
                Masked = false;
            }
        }
    }
}