Exemplo n.º 1
0
        private void InitEventHandler()
        {
            Shown += async(sender, e) =>
            {
                SearchBox.Focus();
                var sentences = await CoreService.GetAllSentence();

                MainListView.BeginUpdate();
                MainListView.Items.Clear();
                MainListView.Items.AddRange(Helper.ConvertSentenceToListViewItem(sentences));
                MainListView.EndUpdate();
                TotalCountLabel.Text = $@"Total {MainListView.Items.Count} Sentences";
            };

            SearchBox.TextChanged += async(sender, e) =>
            {
                var box = sender as TextBox;
                IEnumerable <Sentence> sentences;
                if (box?.Text.Length >= 1)
                {
                    sentences = await CoreService.SearchBySentence(box.Text, Configuration.GetKeywordMaxLength());
                }
                else
                {
                    sentences = await CoreService.GetAllSentence();
                }
                var sentenceList = sentences as IList <Sentence> ?? sentences.ToList();

                MainListView.BeginUpdate();
                MainListView.Items.Clear();
                MainListView.Items.AddRange(Helper.ConvertSentenceToListViewItem(sentenceList));
                MainListView.EndUpdate();

                TotalCountLabel.Text = $@"Total {MainListView.Items.Count} Sentences";
            };

            MainListView.SelectedIndexChanged += (sender, e) =>
            {
                _listViewFoucsed = true;
                var listView = sender as ListView;
                if (listView == null)
                {
                    return;
                }
                if (listView.SelectedIndices.Count == 0)
                {
                    return;
                }
                var index  = listView.SelectedIndices[0];
                var toCopy = MainListView.Items[index].SubItems[1];
                _listViewSelectedRowOffset = index;
                Clipboard.SetText(toCopy.Text);
                SentenceLabel.Text = toCopy.Text;
                StatusLabel.Text   = Constant.Copyed;
            };

            SizeChanged += (sender, e) =>
            {
                MainListView.Columns[1].Width = Size.Width - MainListView.Columns[0].Width - MainListView.Columns[2].Width - 20;
            };
        }