none
WPF視窗拖拉到延伸桌面? RRS feed

  • 問題

  • 環境:VS2010+W7

    我在WPF視窗上擺了一個win32的handle去接影像,但當我將WPF視窗拖拉至另一個螢幕(延伸桌面)時,該影像會停頓,過一下子才繼續撥放,想請問此拖拉到延伸桌面的動作是否會觸發什麼事件,是我沒處理到的,所以才會導ˋ讓致影像停頓?

    P.S 目前我的解決方案,是讓它斷線再重連,但理論上應該不用這樣做,所以想瞭解,將視窗拖拉到延伸桌面它到底會做那些事件,因為有可能是我程式沒處理到這些事件,才會導致正在接收的影像停格。

    感謝

    2012年3月13日 上午 01:00

解答

  • This is a common issue, I found a explain from US forum,

    http://social.msdn.microsoft.com/Forums/ar/wpf/thread/c6f7ea1b-0217-456d-ab5c-4cc7208797b4

    Hi David, it's because WPF MediaElement doesn't have the knowledge of which monitor to draw the video to at start up (since you could display the video on any or all monitors in WPF), so by default, it draws to the primary monitor. However, in the case where it was told to draw on the secondary monitor, it needs to reinitialize the rendering pipeline (re-decoding and re-compositing) which in turn causes the delay. You didn't see this problem with WMP is because WMP has that knowledge and doesn't need to go through the retinitialization process, however, you should notice this problem when you move WMP window accross different monitors while a video is playing. Regarding to DivX, it probably because of the way different decoder work since they are optimized for different things.

    Hope this answers your question.

    Eddie.

    And someone report it could be better if you do turn off hardware acceleration for WPF on the Window that is displaying the video.

        HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
        HwndTarget hwndTarget = hwndSource.CompositionTarget;
        hwndTarget.RenderMode = RenderMode.SoftwareOnly;


    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD


    2012年3月13日 上午 04:38

所有回覆

  • 是否跟顯卡硬體加速設定有關呢?請參考 Graphics Rendering Registry Settings,試著把加速設定給取消試試看。
    2012年3月13日 上午 03:11
  • This is a common issue, I found a explain from US forum,

    http://social.msdn.microsoft.com/Forums/ar/wpf/thread/c6f7ea1b-0217-456d-ab5c-4cc7208797b4

    Hi David, it's because WPF MediaElement doesn't have the knowledge of which monitor to draw the video to at start up (since you could display the video on any or all monitors in WPF), so by default, it draws to the primary monitor. However, in the case where it was told to draw on the secondary monitor, it needs to reinitialize the rendering pipeline (re-decoding and re-compositing) which in turn causes the delay. You didn't see this problem with WMP is because WMP has that knowledge and doesn't need to go through the retinitialization process, however, you should notice this problem when you move WMP window accross different monitors while a video is playing. Regarding to DivX, it probably because of the way different decoder work since they are optimized for different things.

    Hope this answers your question.

    Eddie.

    And someone report it could be better if you do turn off hardware acceleration for WPF on the Window that is displaying the video.

        HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
        HwndTarget hwndTarget = hwndSource.CompositionTarget;
        hwndTarget.RenderMode = RenderMode.SoftwareOnly;


    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD


    2012年3月13日 上午 04:38