public MainWindow() { InitializeComponent(); Status = new HashSet<Status>(); listBox.ItemsSource = Status; View = CollectionViewSource.GetDefaultView(Status); View.SortDescriptions.Add(new SortDescription("CreatedAt.LocalDateTime", ListSortDirection.Descending)); var liveShaping = View as ICollectionViewLiveShaping; if (liveShaping != null && liveShaping.CanChangeLiveSorting) { liveShaping.LiveSortingProperties.Add("CreatedAt.LocalDateTime"); liveShaping.IsLiveSorting = true; } if (Properties.Settings.Default.AccessToken != "" && Properties.Settings.Default.AccessTokenSecret != "") { Tokens = Tokens.Create( TwitterProperties.APIKey, TwitterProperties.APISecret, Properties.Settings.Default.AccessToken, Properties.Settings.Default.AccessTokenSecret); GetHomeTimeLineAsync(); StreamingDisposable = Tokens.Streaming.UserAsObservable() .Where((StreamingMessage m) => m.Type == MessageType.Create) .Cast<StatusMessage>() .Select((StatusMessage m) => m.Status) .Subscribe((Status tweet) => { Application.Current.Dispatcher.Invoke( new Action(() => { if (Status.Contains(tweet)) return; Status.Add(TweetProcessing(tweet)); var selectIndex = listBox.SelectedIndex; if (selectIndex != 0) selectIndex++; View.Refresh(); listBox.SelectedIndex = selectIndex; listBox.ScrollIntoView(listBox.SelectedItem); //カーソルでの位置固定 var lbi = listBox.ItemContainerGenerator.ContainerFromIndex(selectIndex) as ListBoxItem; lbi?.Focus(); }) ); }); } else { var OauthWindow = new OauthWindow(); OauthWindow.Show(); Close(); } }
public MainWindow() { InitializeComponent(); Status = new HashSet <Status>(); listBox.ItemsSource = Status; View = CollectionViewSource.GetDefaultView(Status); View.SortDescriptions.Add(new SortDescription("CreatedAt.LocalDateTime", ListSortDirection.Descending)); var liveShaping = View as ICollectionViewLiveShaping; if (liveShaping != null && liveShaping.CanChangeLiveSorting) { liveShaping.LiveSortingProperties.Add("CreatedAt.LocalDateTime"); liveShaping.IsLiveSorting = true; } if (Properties.Settings.Default.AccessToken != "" && Properties.Settings.Default.AccessTokenSecret != "") { Tokens = Tokens.Create( TwitterProperties.APIKey, TwitterProperties.APISecret, Properties.Settings.Default.AccessToken, Properties.Settings.Default.AccessTokenSecret); GetHomeTimeLineAsync(); StreamingDisposable = Tokens.Streaming.UserAsObservable() .Where((StreamingMessage m) => m.Type == MessageType.Create) .Cast <StatusMessage>() .Select((StatusMessage m) => m.Status) .Subscribe((Status tweet) => { Application.Current.Dispatcher.Invoke( new Action(() => { if (Status.Contains(tweet)) { return; } Status.Add(TweetProcessing(tweet)); var selectIndex = listBox.SelectedIndex; if (selectIndex != 0) { selectIndex++; } View.Refresh(); listBox.SelectedIndex = selectIndex; listBox.ScrollIntoView(listBox.SelectedItem); //カーソルでの位置固定 var lbi = listBox.ItemContainerGenerator.ContainerFromIndex(selectIndex) as ListBoxItem; lbi?.Focus(); }) ); }); } else { var OauthWindow = new OauthWindow(); OauthWindow.Show(); Close(); } }