我想將導航欄隱藏在使用WPF創建的頁面中。我試過ShowsNavigationUI = false
,但它仍然顯示控件。如何隱藏WPF頁面中的導航欄
回答
在Page對象上設置ShowsNavigationUI = false應該這樣做。那裏似乎是一個錯誤,但是,會導致這種情況在事件中的至少一個序列失敗:當此設置
- 頁已經在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>
以上僅適用於導航窗口,但我用普通的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>
這是否允許您動態加載和關閉頁面,同時保持主頁面打開?爲清晰起見,請致電 – 2016-07-18 16:49:36
這一個我覺得很容易。在你的主窗口,這樣做:
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;
}
+1。 – jogojapan 2012-11-07 05:31:16
你可以更改框架的默認樣式以刪除導航按鈕(如下所示)。 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>
只是告訴在你的頁面的容器,你希望導航欄或不使用 NavigationUIVisibility財產。
<Frame Margin="173,41,1,28" Name="frmPageContainer" NavigationUIVisibility="Hidden" Panel.ZIndex="1" >
我有這個問題,每當我動態改變一幀的內容屬性,並通過使用我的點擊()事件下面的代碼解決了這個問題。
ContentFrame.NavigationUIVisibility = NavigationUIVisibility.Hidden;
其中ContentFrame是在XAML中定義的框架的名稱。即
<Frame x:Name="ContentFrame" />
這是一個非常簡單的實現。
這裏:
<Frame x:Name="_FrameName" NavigationUIVisibility="Hidden" />
:-P
- 1. 如何隱藏導航欄?
- 2. 如何隱藏Ionic2中的導航欄
- 3. 如何隱藏頁面頂部的導航欄
- 4. 隱藏導航欄?
- 5. 如何在android中隱藏導航欄?
- 6. Xamarin Forms主頁細節頁面主頁隱藏導航欄
- 7. 如何隱藏lightSlder的導航欄?
- 8. 如何隱藏導航欄上的UIbarbutton
- 9. 如何隱藏角度2材質中的側面導航欄
- 10. Ruby/Rails - 在根頁面上隱藏導航欄和頁腳
- 11. 如何使用Jquery隱藏導航欄?
- 12. 如何通過CAAnimation隱藏導航欄?
- 13. 如何解決Bootstrap導航欄隱藏
- 14. WPF頁面標題欄隱藏
- 15. 隱藏導航欄旋轉
- 16. 問題隱藏導航欄
- 17. SFSafariViewController:隱藏導航欄
- 18. IPHONE:ABPeoplePickerNavigationController隱藏導航欄
- 19. Nativescript - 隱藏導航欄(IOS)
- 20. 如何隱藏登錄和註冊頁面中的導航欄反應?
- 21. 隱藏導航欄中的按鈕
- 22. 導航欄中的SegmentedControll隱藏view.title
- 23. 如何在Liferay的導航菜單中隱藏的頁面中隱藏導航菜單?
- 24. 頁面菜單,滾動時隱藏導航欄
- 25. W3 CSS W3-導航欄與W3-頂部隱藏頁面內容
- 26. Silverlight helix代碼隱藏頁面導航
- 27. UITableViewController隱藏導航欄[搜索欄]
- 28. WPF頁面導航
- 29. 如何在第一頁顯示之前隱藏導航欄?
- 30. 如何在一個wordpress頁面中隱藏導航菜單?
我找不到ApplicationPriority。它是什麼類?我有同樣的問題,但對我來說這是隨機的。 – Paparazzi 2011-10-13 16:16:26
通過'DispatcherPriority.Loaded'更改'ApplicationPriority.Render' – 2014-03-14 13:36:39