// In sliverligh there is no readily available change event for DataContext.
        // To create it I had to write an interface and a static class.
        // Interface contains one method with is implemented below, this
        // method is called be the control itself. To made this, I had to
        // register my control in static class 'DataContextChangedHelper'(in constructor)
        // with call method when DataContext will be changed.
        public void DataContextChanged(DownloadListItemControl sender, DependencyPropertyChangedEventArgs e)
        {
            QueuedDownload model = (DataContext as QueuedDownload);

            model.PropertyChanged += OnDownloadedProgressTextChanged;
            SetDownloadedProgressText(model);
        }
 private void SetDownloadedProgressText(QueuedDownload model)
 {
     if (model.DownloadSize == long.MaxValue)
     {
         DownloadedProgressText = KIndeterminateDownloadSize;
     }
     else
     {
         DownloadedProgressText = String.Format("{0} / {1} kB", model.DownloadedBytes / 1024, model.DownloadSize / 1024);
     }
 }
        private void OnDownloadMenuActivated(object sender, RoutedEventArgs args)
        {
            MenuItem menuItem = sender as MenuItem;

            Debug.Assert(menuItem != null);
            QueuedDownload downloadItem = menuItem.CommandParameter as QueuedDownload;

            Debug.Assert(downloadItem != null);

            switch (menuItem.Tag.ToString())
            {
            case "Cancel":
                App.Engine.CancelDownload(downloadItem);
                break;
            }
        }
コード例 #4
0
        private void OnDownloadClicked(object sender, SelectionChangedEventArgs args)
        {
            if (DownloadsList.SelectedIndex != -1)
            {
                QueuedDownload clickedDownload = DownloadsList.SelectedItem as QueuedDownload;
                Debug.Assert(clickedDownload != null);

                // pause/resume download
                if (clickedDownload.State == QueuedDownload.DownloadState.Paused || clickedDownload.State == QueuedDownload.DownloadState.Stopped)
                {
                    App.Engine.StartDownload(clickedDownload);
                }
                else
                {
                    App.Engine.StatisticsManager.LogDownloadEnd(clickedDownload);
                    App.Engine.StopDownload(clickedDownload);
                }

                // set selected index to -1 to enable repeated clicks on item
                DownloadsList.SelectedIndex = -1;
            }
        }