2015-01-02 7 views
0

WP8에 메시지 상자를 표시 할 수있는 방법이 있는지 궁금합니다. 즉 앱을 여는 순간입니다.MessageBox Display Once

다음 코드는 이미 매우 기본적인 것입니다.

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    MessageBox.Show("Hi"); 
} 

그러나 앱이 열릴 때마다 표시됩니다. 나는 단지 그것이 처음으로 보여주기를 바랄뿐입니다.

는 것이 가능할까요?

+0

이미 bool에서 messagebox를 표시했는지 기억할 수 있습니다. 또는 객체를 시각적 트리에 추가 할 때 발생하는 Loaded 이벤트를 사용하십시오. –

답변

0

WP 8.0 Silverlight 앱에서이 기능을 성공적으로 사용했습니다. , OneTimeDialog를 재사용 가능한 클래스를 작성하십시오 "힌트"또는 대화 상자가 한 번만 다른 많은 도움이된다 "환영"을 표시

OneTimeDialog.Show("WelcomeDialog", "Welcome", "Welcome to my app! You'll only see this once.") 

:

using System.Windows; 
using System.IO.IsolatedStorage; 

namespace MyApp 
{ 
    public static class OneTimeDialog 
    { 
     private static readonly IsolatedStorageSettings _settings = IsolatedStorageSettings.ApplicationSettings; 

     public static void Show(string uniqueKey, string title, string message) 
     { 
      if (_settings.Contains(uniqueKey)) return; 

      MessageBox.Show(message, title, MessageBoxButton.OK); 

      _settings.Add(uniqueKey, true); 
      _settings.Save(); 
     } 
    } 
} 

는 다음과 같이 앱 어디에서나 사용 애플 리케이션의 종류, 그래서 실제로 위의 코드를 휴대용 클래스 라이브러리에 여러 프로젝트에서 참조 할 수 있습니다.

+0

브래드 감사합니다. –

+0

상자의 텍스트 레이아웃 즉 단락/글 머리 기호 등의 서식을 지정하는 방법이 있습니까? –

+0

지금 당장은 아니지만,이 nuget 패키지의 CustomMessageBox 클래스 (https://www.nuget.org/packages/WPtoolkit)를 살펴보십시오. 그것은 더 많은 옵션을 제공하고 그것이 그 행동을 지원할 수 있다면 나는 놀라지 않을 것입니다. – Brad

1

여러 세션에서 상태를 유지해야하므로 isolated storage 키 - 값 쌍이 좋습니다. 이전에 확인한 다음 업데이트 :

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    var settings = IsolatedStorageSettings.ApplicationSettings; 
    if (settings.ContainsKey("messageShown") && (bool)settings["messageShown"] == true)  
    { 
    MessageBox.Show("Hi"); 
    settings["messageShown"] = true; 
    } 
} 
+0

도움을 주셔서 감사합니다. 그러나 해당 코드를 시도한, ContainsKey 다음 오류를 반환합니다. 'System.IO.IsolatedStorage.IsolatedStorageSettings' 'System.IO.IsolatedStorage 형식의 첫 번째 인수를 받아들이는'ContainsKey '및 확장 메서드'ContainsKey '정의가 포함되어 있지 않습니다. .IsolatedStorageSettings '을 찾을 수 있습니다 (사용 지시문이나 어셈블리 참조가 누락 되었습니까?) –

+0

'포함 '만 사용하려고했지만 코드가 실행되지만 메시지 상자가 표시되지 않습니다. –

+0

도움이된다면 Silverlight WP8.0 앱을 사용하고 있습니다. –