實現Metro中MediaElement的進度條

 最近開始做Metro的項目,有很多的東西都不是很清楚,相信有很多搞Metro項目的開發人員也在不斷的摸索中前行。
 今天要研究的是在Metro系統自帶的MediaElement(mediaplay發現有很多問題,故棄之不研究)實現進度條的同步,之前有看到網上說通過定時檢測多媒體當前的時間來刷新進度條,後來研究了一下wpf(Metro很多的東西都是借鑑wpf的)的依賴屬性,發現可以將slide的value和mediaelement的position屬性關聯,所以實現進度條的同步就很簡單了,以下是代碼,先貼出來。現在項目比較緊,有時間再整理。

private void BindingPosition()
        {
            //bing MediaElement.Position to MediaPositionProperty

            Binding binding = new Binding
            {
                Source = myMediaElement,
                Path = new PropertyPath("Position"),
            };

            BindingOperations.SetBinding(this, VideoDisplayPage.MediaPositionProperty, binding);

            //following is same
            //Binding binding = new Binding();
            //binding.Path = new PropertyPath("Position");
            //binding.Source = myMediaElement;
        }

        private void ClearBinding()
        {
            //Clear the binding
        }

        public TimeSpan MediaPosition
        {
            get { return (TimeSpan)GetValue(MediaPositionProperty); }
            set { SetValue(MediaPositionProperty, value); }
        }

        public static readonly DependencyProperty MediaPositionProperty =
            DependencyProperty.Register("MediaPosition", typeof(Object), typeof(VideoDisplayPage), new PropertyMetadata(null, new PropertyChangedCallback(MediaPositionChangeCallback)));

        private static void MediaPositionChangeCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //throw new NotImplementedException();
            if (d.GetType() == typeof(VideoDisplayPage))
            {
                VideoDisplayPage play = (VideoDisplayPage)d;
                TimeSpan span = (TimeSpan)e.NewValue;
                play.SetMediaPlayProgressPosition(span);
            }
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章