1
我爲Windows Phone製作了一個上傳應用程序,該功能位於B類(SecondPage)中,我有一個上傳任務,當這個任務完成時,它調用一個事件並通知A類(MainPage)完成任務並做一些事情,環顧網站,我發現了一些解決方案,但他們沒有太大的幫助(只是我認爲)。如何從其他頁面調用事件Windows Phone?
這裏是我在SecondPage
public sealed partial class SecondPage : Page
{
public event EventHandler clearHandler = delegate { };
public SecondPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void btnClear_Tapped(object sender, TappedRoutedEventArgs e)
{
//some works
if (clearHandler != null)
clearHandler(this, null);
}
}
代碼在MainClass
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SecondPage sp = new SecondPage();
sp.clearHandler += Sp_clearHandler;
}
private void Sp_clearHandler(object sender, EventArgs e)
{
txt.Text = "";
}
private void btnJump_Tapped(object sender, TappedRoutedEventArgs e)
{
Frame.Navigate(typeof(SecondPage));
}
}
文本框名爲TXT不會被清除,可你們,請幫幫我,謝謝!