2017-04-21 47 views
1

我正在爲MediaPlayerElement創建CustomMediaTransportControls。在這我想要一個按鈕來創建CompactOverlay框架,所以我將下面的代碼添加到public sealed class CustomMediaTransportControls : MediaTransportControls嘗試讀取或寫入受保護的內存。這通常表示其他內存已損壞

public async void CompactOverlayButton_ClickAsync(object sender, RoutedEventArgs e) 
{ 
    await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => 
    { 
     var frame = new Frame(); 
     compactViewId = ApplicationView.GetForCurrentView().Id; 
     frame.Navigate(typeof(VideoPlayerPage)); 
     Window.Current.Content = frame; 
     Window.Current.Activate(); 
     ApplicationView.GetForCurrentView().Title = ""; 
    }); 
    bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay); 
} 

但是,當我使用這些代碼時,我在XAML部分中收到錯誤消息。 enter image description here 如果我沒有使用上述功能,則不會有錯誤。

解決方案的嘗試:

  1. 在PowerShell中

    運行netsh winsock reset
  2. 結算解決方案和重建方案

僅供參考:

這裏是我的全部代碼

  1. CustomMediaTransportControls.cs - ResourceDictionary
  2. MediaPlayerDictionary.xaml - 從MediaTransportControls派生類
  3. VideosPage.xaml - 頁面,CustomMediaTransportControls已使用
+0

'CustomVideoControls'是你開發的東西嗎?它是否使用了不安全的{}塊? – Milney

+0

@Milney我會附上問題 –

+0

中的全部代碼,你能提供完整的xaml代碼嗎? – Hannes

回答

0

,而不用聲明一個變量compactViewId的你班級你應該只在本地申報:

p̶u̶b̶l̶i̶c̶ ̶i̶n̶t̶ ̶c̶o̶m̶p̶a̶c̶t̶V̶i̶e̶w̶I̶d̶ ̶=̶ ̶A̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶V̶i̶e̶w̶.̶G̶e̶t̶F̶o̶r̶C̶u̶r̶r̶e̶n̶t̶V̶i̶e̶w̶(̶)̶.̶I̶d̶; /̶/̶ I̶n̶i̶t̶i̶a̶l̶i̶z̶i̶n̶g̶ ̶c̶o̶m̶p̶a̶c̶t̶V̶i̶e̶w̶I̶d̶ ̶t̶o̶ ̶t̶h̶e̶ ̶C̶u̶r̶r̶e̶n̶t̶ ̶V̶i̶e̶w̶ ̶I̶D̶ 

//Button click event for CompactOverlayButton to Create a Frame in CompactOverlay mode 
public async void CompactOverlayButton_ClickAsync(object sender, RoutedEventArgs e) 
{ 
    await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => 
    { 
     var frame = new Frame(); 
     frame.Navigate(typeof(MainPage)); 
     Window.Current.Content = frame; 
     Window.Current.Activate(); 
     ApplicationView.GetForCurrentView().Title = ""; 
    }); 
    bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(ApplicationView.GetForCurrentView().Id, ApplicationViewMode.CompactOverlay); 
} 
+0

謝謝,它的工作原理。你可以請幫助我與[設置可視性=「摺疊」不隱藏按鈕](http://stackoverflow.com/questions/43562297/setting-visibility-collapsed-doesnt-hide-the-button)這個問題。 –

相關問題