2016-11-18 23 views
0

我在我的WPF項目中有MainWindow,進入這個類有一個Frame。WPF |附加一個框架到更多頁面

<Window x:Class="Gestionale.MainWindow> 
    <Grid> 
     <Frame x:Name="frameChanger"/> 
     <Button x:Name="Prenotation"/> 
    </Grid> 
</Window> 

當我點擊按鈕添加幀顯示了此功能的頁面Prenotation:

public partial class MainWindow : Window 
{ 

private void Add_Click(object sender, RoutedEventArgs e) 
    { 
     enabled_button(); 
     camereButton.IsEnabled = false; 
     try 
     { 
      frameChanger.Navigate(new framePrenotation()); 
     } 
     catch(Exception ex) { MessageBox.Show("Error!"); } 
    } 
} 

頁prenotation還有其他3鍵:

<Page x:Name="Gestionale.AddPrenotation"> 
    <Grid> 
     <Button x:Name="DeletePrenotation"/> 
     <Button x:Name="AlterPrenotation"/> 
     <Button x:Name="AddPrenotation"/> 
    </Grid> 
</Page> 

我需要frameChanger引用當我點擊「AddPrenotation」時添加到AddPrenotation頁面。我該怎麼做?

任何指導,可以理解

感謝,達維德

+0

所以你需要頁面添加另一個本身的實例?即時通訊措辭困惑 – maximdumont

+0

好吧,我有一個框架打開,我在裏面工作。在這個框架中有一個按鈕,我不會在點擊這個按鈕時使用.navigation(Page p)改變框架。但主體框架的實例位於主體頁面中,我不能調用框架,因爲它不是公共靜態元素。我能怎麼做? –

回答

0

嘗試與參數的構造函數寫到Page

frameChanger.Navigate(new framePrenotation(frameChanger));` 

...

public partial class framePrenotation: Page 
{ 
    private Frame frameParent; 
    public framePrenotation(Frame frame) 
    { 
     this.frameParent= frame; 
     ... 
    } 
    ... 
} 

,但我不你明白爲什麼你應該這樣做...

相關問題