2017-12-02 123 views
0

點擊我想在調整大小按鈕的點擊啓動消息對話框..檢測上調整窗口大小UWP

我插在任意點擊消息對話框中,但我怎麼能啓動它在調整窗口大小?

Resize button

代碼:

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 

    private async void Button_Click(object sender, RoutedEventArgs e) 
    { 
     var messageDialog = new MessageDialog("This is a Message dialog"); 
     await messageDialog.ShowAsync(); 
    } 
} 

我走近一個可能的解決方案,但是,我只需要調整大小按鈕點擊,這可能嗎?

代碼:提前

Window.Current.CoreWindow.SizeChanged += (ss, ee) => 
{ 
     var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView(); 
     if (appView.IsFullScreen) 
     { 
      //show message 
     } 
     ee.Handled = true; 
}; 

謝謝!

回答

1

您可以訂閱頁面大小更改事件此

XAML

<Page 
x:Class="App.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:SO15" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" SizeChanged="Page_SizeChanged"> <!-- SizeChanged event --> 

C#

private void Page_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    Window.Current.CoreWindow.SizeChanged += async (ss, ee) => 
    { 
     var appView = ApplicationView.GetForCurrentView(); 
     if (appView.IsFullScreen) 
     { 
      var messageDialog = new MessageDialog("Window is Maximized"); 
      await messageDialog.ShowAsync(); 
     } 
     ee.Handled = true; 
    }; 
    Window.Current.CoreWindow.SizeChanged += async (ss, ee) => 
    { 
     var appView = ApplicationView.GetForCurrentView(); 
     if (!appView.IsFullScreen) 
     { 
      var messageDialog = new MessageDialog("Window is not Maximized"); 
      await messageDialog.ShowAsync(); 

     } 
     ee.Handled = true; 
    }; 
} 

或者處理在C#中推薦

使用此事件

Window.Current.CoreWindow.SizeChanged += CoreWindow_SizeChanged;

bool msgboxshown = false; //add this condition in above solution also if msg dialog shown multiple times at the time of mazimizing window 

    private async void CoreWindow_SizeChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowSizeChangedEventArgs args) 
    {    
     var appView = ApplicationView.GetForCurrentView(); 

     if (!appView.IsFullScreen && !msgboxshown) 
     { 
      var messageDialog = new MessageDialog("Window is not maximized"); 
      msgboxshown = true;     
      await messageDialog.ShowAsync(); 
      msgboxshown = false; 
     } 

     if (appView.IsFullScreen && !msgboxshown) 
     { 
      var messageDialog = new MessageDialog("Windows is maximized"); 
      msgboxshown = true;     
      await messageDialog.ShowAsync(); 
      msgboxshown = false; 

     } 
     args.Handled = true; 
    } 

/* You can remove msgboxshown condition , it is because message dialog will show continuously multiple times */