2010-06-17 292 views

回答

16

在Page對象上設置ShowsNavigationUI = false應該這樣做。那裏似乎是一個錯誤,但是,會導致這種情況在事件中的至少一個序列失敗:當此設置

  • 頁面導航之間來回
    1. 頁已經在NavigationWindow

    可能還有其他場景我還沒有遇到,但它使它失敗。

    爲了完全可靠地工作,我所做的是完全忽略Page.ShowsNavigationUI屬性,並將其設置在NavigationWindow上。這似乎是完全可靠的。

    這裏是如何可以在頁面的構造函數來完成:

    Dispatcher.BeginInvoke(ApplicationPriority.Render, new Action(() => 
    { 
        var navWindow = Window.GetWindow(this) as NavigationWindow; 
        if(navWindow!=null) navWindow.ShowsNavigationUI = false; 
    })); 
    

    如果你這樣做,切記不要設置任何ShowsNavigationUI Page對象上。通過更改其ControlTemplate,您也可以通過任何您喜歡的方式重新設置您的導航窗口。例如,這一切刪除,但實際頁面內容:

    <Style TargetType="{x:Type NavigationWindow}"> 
        <Setter Property="Template"> 
         <Setter.Value> 
         <ControlTemplate TargetType="{x:Type NavigationWindow}"> 
    
          <AdornerDecorator> 
          <ContentPresenter Name="PART_NavWinCP" 
               ClipToBounds="true"/> 
          </AdornerDecorator> 
    
         </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
        </Style> 
    
    +0

    我找不到ApplicationPriority。它是什麼類?我有同樣的問題,但對我來說這是隨機的。 – Paparazzi 2011-10-13 16:16:26

    +0

    通過'DispatcherPriority.Loaded'更改'ApplicationPriority.Render' – 2014-03-14 13:36:39

    3

    以上僅適用於導航窗口,但我用普通的WPF窗口。有人說這些比導航窗口更好。我使用DockPanel來託管我的頁面。我的解決方案爲DockPanel創建了一個新模板,並且不添加按鈕或隱藏它們(請參閱StackPanel Visibility =「Hidden」)。它很好地工作。

    <DockPanel>  
        <Frame x:Name="_mainFrame"> 
        <Frame.Template> 
    
         <ControlTemplate TargetType="Frame"> 
          <DockPanel Margin="7"> 
           <StackPanel Visibility="Hidden" 
            Margin="0" 
            Orientation="Horizontal" 
            DockPanel.Dock="Top" 
            > 
            <!--<Button 
             Content="Avast! Go back!" 
             Command="{x:Static NavigationCommands.BrowseBack}" 
             IsEnabled="{TemplateBinding CanGoBack}" 
             /> 
            <Button 
             Content="Forward you dogs!" 
             Command="{x:Static NavigationCommands.BrowseForward}" 
             IsEnabled="{TemplateBinding CanGoForward}" 
             />--> 
           </StackPanel> 
    
           <Border> 
            <ContentPresenter /> 
           </Border> 
          </DockPanel> 
         </ControlTemplate> 
    
         </Frame.Template> 
        </Frame> 
    </DockPanel> 
    
    +0

    這是否允許您動態加載和關閉頁面,同時保持主頁面打開?爲清晰起見,請致電 – 2016-07-18 16:49:36

    5

    這一個我覺得很容易。在你的主窗口,這樣做:

    public MainWindow() 
        public partial class MainWindow : NavigationWindow 
        { 
         public MainWindow() 
         { 
          InitializeComponent(); 
    
          ShowsNavigationUI = false; 
         } 
        } 
    } 
    

    如果您有按鈕的事件點擊打開一個新的頁面,只是這樣做:如果您使用的是框架

    private void btnEndUserSearch_Click(object sender, RoutedEventArgs e) 
    { 
          EndUser EndUserSearchPage = new EndUser(); 
          this.NavigationService.Navigate(EndUserSearchPage); 
          EndUserSearchPage.ShowsNavigationUI = false; 
    } 
    
    +0

    +1。 – jogojapan 2012-11-07 05:31:16

    7

    你可以更改框架的默認樣式以刪除導航按鈕(如下所示)。 NavigationWindow也可以採用相同的方法。我最初嘗試設置Page.ShowsNavigationUI,它沒有效果。只需將以下樣式添加到ResourceDictionary中即可,並且工作正常。

    <Style TargetType="{x:Type Frame}"> 
        <Setter Property="Control.Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type Frame}"> 
         <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}"> 
          <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Name="PART_FrameCP" /> 
         </Border> 
         </ControlTemplate> 
        </Setter.Value> 
        </Setter> 
    </Style> 
    
    68

    只是告訴在你的頁面的容器,你希望導航欄或不使用 NavigationUIVisibility財產。

    <Frame Margin="173,41,1,28" Name="frmPageContainer" NavigationUIVisibility="Hidden" Panel.ZIndex="1" > 
    

    0

    我有這個問題,每當我動態改變一幀的內容屬性,並通過使用我的點擊()事件下面的代碼解決了這個問題。

    ContentFrame.NavigationUIVisibility = NavigationUIVisibility.Hidden; 
    

    其中ContentFrame是在XAML中定義的框架的名稱。即

    <Frame x:Name="ContentFrame" /> 
    
    22

    這是一個非常簡單的實現。

    這裏:

    <Frame x:Name="_FrameName" NavigationUIVisibility="Hidden" /> 
    

    :-P