Example #1
0
        public MainWindow()
        {
            InitializeComponent();
            AppState = new State();

            TaskGrid.ItemsSource = Tasks;

            // Implement "sticky" scrolling. If the control is scrolled to the bottom, keep it that
            // way when new items are added. Otherwise, don't change the scroll position.
            // HACK: Wait a second for the initial cached to be populated, otherwise this takes ages.
            Task.Delay(3000).ContinueWith(_ =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    var viewer = GetScrollViewer(TaskGrid);
                    Tasks.CollectionChanged += (sender, args) =>
                    {
                        if (viewer.VerticalOffset >= viewer.ScrollableHeight - 1)
                        {
                            TaskGrid.ScrollIntoView(Tasks.Last());
                        }
                    };
                });
            });
            Task.Run(() => DoNetwork());
        }