示例#1
0
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            // через диалог открытия папки
            FolderBrowserDialog dlg = new FolderBrowserDialog();

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DirectoryInfo dir = new DirectoryInfo(dlg.SelectedPath);

                // получаю путь и перебираю все файлы в полученной папке
                foreach (FileInfo fInfo in dir.GetFiles())
                {
                    if (fInfo.Extension == ".xaml") // если xaml
                    {
                        MyFlowDocument fDoc = new MyFlowDocument();
                        fDoc.Load(fInfo);
                        myListDocument.Add(fDoc);
                        this.listBox.Items.Add(fDoc);
                    }
                }
            }
        }
示例#2
0
        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listBox.SelectedItem != null)
            {
                //определение индекса выбранного элемента и вывод на экран через image1
                int            index = listBox.SelectedIndex;
                MyFlowDocument fDoc  = new MyFlowDocument();
                fDoc = listBox.Items[index] as MyFlowDocument;
                if (!fDoc.Error)
                {
                    TextRange textRange = new TextRange(docBox.ContentStart, docBox.ContentEnd);
                    //Doc = XamlReader.Load(new FileStream(fStream.FullName, FileMode.Open)) as FlowDocument;
                    using (FileStream fs = new FileStream(fDoc.Info, FileMode.Open))
                    {
                        textRange.Load(fs, System.Windows.DataFormats.Xaml);
                    }
                }
                else
                {
                    docBox.Blocks.Clear();
                    Paragraph paragraph = new Paragraph();
                    paragraph.Background = Brushes.Red;
                    paragraph.Inlines.Add(fDoc.Info);
                    docBox.Blocks.Add(paragraph);

                    DoubleAnimation buttonAnimation = new DoubleAnimation();
                    buttonAnimation.From           = button.ActualHeight;
                    buttonAnimation.To             = button.ActualHeight - 40;
                    buttonAnimation.AutoReverse    = true;
                    buttonAnimation.RepeatBehavior = new RepeatBehavior(5);
                    buttonAnimation.FillBehavior   = FillBehavior.Stop;
                    buttonAnimation.Duration       = TimeSpan.FromSeconds(0.05);
                    button.BeginAnimation(System.Windows.Controls.Button.HeightProperty, buttonAnimation);
                }
            }
        }