Beispiel #1
0
        /// <summary>
        /// 构造函数入口
        /// </summary>
        /// <param name="book">书籍信息</param>
        /// <param name="mainWindow">主窗口对象</param>
        /// <param name="config">配置项</param>
        public ReadingPage(Book book, MainWindow mainWindow = null, Config config = null)
        {
            InitializeComponent();

            Thread thread = new Thread(new ThreadStart(delegate
            {
                try
                {
                    this.book       = book;
                    this.mainWindow = mainWindow;
                    this.config     = config;
                    //获取目录
                    DataFetch.GetList(book);
                    bookSource = DataFetch.GetBookSource(book.Source);

                    //主要为遍历目录
                    int i = 0;
                    foreach (KeyValuePair <string, string> kvp in book.ListUrl)
                    {
                        if (kvp.Key.Trim().Length > 2)
                        {
                            i++;
                            NewId.Add(i, kvp.Key);
                        }
                    }
                    Dispatcher.Invoke((Action) delegate
                    {
                        if (book.Read == 0)
                        {
                            Jump(1);
                        }
                        else
                        {
                            Jump((int)book.Read);
                        }
                    });
                }
                catch (Exception ex)
                {
                    Tool.TextAdditional(ex.Message);
                }
            }));

            thread.IsBackground = true;  //是否为后台线程
            thread.Start();

            this.Closed += BeforeClosing;
            //newText.IsEnabled = false;

            //窗口大小改变时
            this.SizeChanged += new SizeChangedEventHandler(ReadingPage_Resize);

            //设置定时器(朗读)
            timer          = new DispatcherTimer();
            timer.Interval = new TimeSpan(10000000);   //时间间隔为一秒
            timer.Tick    += new EventHandler(timer_Tick);
        }