I started using WinUI 3 to build a desktop program to replace the old WinForm program. I use NavigationView in the main Window to manage the pages in the program. The first page (frame) displayed will be a login screen. I want to disable the navigation menu and enabled when user login successful. My problem is how can I access the navigation menu in the frame (the page in the frame FMMain)?
<NavigationView x:Name="NVMenu" PaneDisplayMode="LeftCompact" IsSettingsVisible="False" IsPaneOpen="False">
<NavigationView.MenuItems>
<NavigationViewItem x:Uid="NVIHome" x:Name="NVIHome">
<NavigationViewItem.Icon>
<FontIcon x:Uid="FIHome"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.MenuItems>
<Frame x:Name="FMMain" />
</NavigationView>
Thank you.
You can have a global static property, which your login frame can access. Then, bind the 'Enabled' property of your Navigation view item to it.
Add a folder under the project: "Views"
Then add an empty page (C# - WinUI - Blank Page) and rename it.
Now the project folder looks like this:
Project Name
Properties
Assets
Views
BlankPage1.xaml
BlankPage1.xaml.cs
BlankPage2.xaml
BlankPage2.xaml.cs
App.xaml
App.xaml.cs
MainWindow.xaml
MainWindow.xaml.cs
MainWindow.xaml
<NavigationView IsBackButtonVisible="Collapsed" IsSettingsVisible="False" ItemInvoked="nav_iteminvoked">
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="Page1" Tag="WinUI3.Views.BlankPage1"/>
<NavigationViewItem Icon="Play" Content="Page2" Tag="WinUI3.Views.BlankPage1"/>
</NavigationView.MenuItems>
<Frame x:Name="contentFrame"/>
</NavigationView>
Change the "WinUI3" in navigation view item tags to your project name.
MainWindow.xaml.cs
using System;
private void nav_iteminvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
{
Type newPage = Type.GetType(args.InvokedItemContainer.Tag.ToString());
contentFrame.Navigate(newPage, null, args.RecommendedNavigationTransitionInfo);
}
Don't do that, winui3 is not production ready. I am strugling with many issues.
To name a few - scrollview does not work properly (does not work at all, to be specific), badges are not implemented yet, window icon must be set with win32, if you need data table, community toolkit is only free way, but it does not support net6 yet...
Related
I am working on some WPF app with a main window and with some pages, something weird happened to me, "suddenly" when I move from page 1 to page two this toolbar added himself to my window,
my questions: where did this came from? how to remove/ give it better design, I mean where is the source code of this toolbar
Is this default by Microsoft?
Here is my window class def:
<Window x:Class="Tool.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Tool"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
ResizeMode="CanResizeWithGrip"
MinWidth="600"
MinHeight="500"
Title="Preparation Tool" Height="600" Width="1080" Icon="icon.ico" Foreground="White" >
You can easily hide that:
<Frame NavigationUIVisibility="Hidden"
But you should use contentcontrol instead of frame and usercontrols instead of pages.
Where did this came from? How to remove it?
It is a built-in navigation chrome in Frame control.
According to Microsoft docs, the navigation chrome is visible when a Frame uses its own journal (see JournalOwnership).
If you don't want that Navigation chrome, you can simply set NavigationUIVisibility property of your frame to Hidden.
<Frame NavigationUIVisibility="Hidden" />
If you don't want history navigation management of the current Frame too, you can set JournalOwnership property of Frame to UsesParentJournal . This makes your Frame use the journal of the next available navigation host up the content tree, if available. Otherwise, navigation history is not maintained for the Frame.
<Frame JournalOwnership="UsesParentJournal" />
Or give it a better design? I mean where is the source code of this toolbar?
In Visual Studio (or Visual Studio Blend that I prefer for UI design stuff) simply right-click on your Frame and then select Edit Template > Edit a copy and put copy of Template in a ResourceDictionary. Then you can modify the template which it's key is FrameNavChromeTemplateKey.
Is this default by Microsoft?
Yes.
P.S. Do not forget that when you set NavigationUIVisibility="Hidden" and JournalOwnership="OwnsJournal", history management for Frame itself is still available and you can navigate between pages with commands like Next/Prev mouse buttons.
I have a Windows universal UWP app that I am using Pivot on to give me the ability to swipe from page to page for navigation. Let's say I have three UI pages (page1, page2 and page3), I then have three PivotItems, one for each. The question is, inside of the PivotItem, I currently have a Frame in each and am using the Frame to show the UI page. This is working, however, this seems redundant because as I understand it, a Frame is used to dynamically show content such as a UI. It seems that you would have EITHER buttons or links for the tabs in a grid and then use one frame to rotate the UI views depending on which button is clicked OR you would use pivot, which I am doing. Main reason I chose pivot, I am targeting mobile and I do want to be able to swipe from page to page.
So, what I don't know is, when using pivot, what do I put in each PivotItem? Is a frame on each correct? Or should I use some other item like UIElement?
Thanks!
What I want to know specifically is instead of stuffing controls directly in the PivotItem, how do I just have each PivotItem reference and use my other pages?
Pivot is a ItemsControl.so it can contain a collection of items of any type, including the Page. You can use pages in PivotItem like below:
<Page
x:Class="ProjectName.MainPage"
xmlns:local="using:ProjectName"
...
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Pivot x:Name="rootPivot" Title="Pivot Title">
<PivotItem Header="Pivot Item 1">
<!--reference the page with local:PageName-->
<local:PageOne></local:PageOne>
</PivotItem>
<PivotItem Header="Pivot Item 2">
<local:PageTwo></local:PageTwo>
</PivotItem>
<PivotItem Header="Pivot Item 3">
<local:PageThree></local:PageThree>
</PivotItem>
</Pivot>
</Grid>
Hi I'm a newbie to windows store apps and i want to create a pop up that'll show image .I'm currently using Prism framework and tried many things.However , I'm successfully able to launch the pop up using code behind file but i need it from View Model class. Please help.
You can use default winrt popups but if you want popups developed by yourself this is the way.
Create modal dialog user control, structure is following
<Grid>
<Grid Background="Black" Opacity="0.4"/>
<Grid HorizontalAlignment="Center" VerticelAlignment="Center">
<!-- your popup xaml -->
</Grid>
</Grid>
Of course, you have to set ViewModel in some way, e.g. through ViewModelLocator
DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=ModalDialog}">
Add this user control to your main view ( root view ) or to all views where you want to have popup.
<controls:ModalDialog Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"/>
After this you can implement some service or use messenger to show dialogs. I know that it is maybe not so understandable but it is difficult to describe in all details. Feel free to ask.
I heed to create wizard and in the wizard I have tab control which have to call to the user control according to the context,I need to create the wizard which will able to invoke
different pages according to the user selection ,currently I call to the pages as follows which I think is not the right way,any Idea how should I do it via code (not in the xaml )i.e. according to some decision invoke the suitable page to the tab control.
this is the xaml:
<Border Grid.Column="1" Name="MainBorder">
<TabControl x:Name="MainTabControl" Height="638" VerticalAlignment="Bottom">
<TabItem Visibility="Collapsed" >
<Frame Source="page1.xaml" />
</TabItem>
<TabItem Visibility="Collapsed" >
<Frame Source="page2.xaml"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 3">
<TextBlock Text="Page 3"/>
</TabItem>
<TabItem Visibility="Collapsed" Header="Step 4">
<TextBlock Text="Page 4"/>
</TabItem>
</TabControl>
</Border>
UPDATE
I was tried in the main window like the following without success
create new tab by code and add to it the page 1 and then add it to the MainTabControl
TabControl tabControl = new TabControl(new Page1());
MainTabControl.add..
.
there is no add in the main tab control
For this scenario, I would use a Frame rather that tabs. The frame allows you to manage the flow of it's content via the NavigationService. You can use Uri's to display a page via the Frame.Source property, or a FrameworkElement via the Frame.Content property. Both are DependencyProperties and can therefore be bound to.
Paul Stovel wrote an excellent blog on this called WPF Navigation. Everything you need to create a wizard from a frame can be found in this blog, including passing values between pages and templating of the Frame to simply handle the display of navigation buttons.
I would agree with Mark, it is a lot easier to use NavigationWindows than TabControls.
I've worked on a lot of interfaces like this and written up some of the basic things with,
WPF Wizards, Part 1
WPF Wizards, Part 2
Then more recently I worked out how to get the styling just right
Styling Wizards
In fact I've released the styling and examples as open source at
WinChrome
There is some simple example code including use of a navigation list to the left with,
WinChrome.Win7Demo
Hope this helps
So I have a Panorama control and the PanoramaItems are programmatically added to the control using the following template.
<UserControl>
<Grid x:Name="LayoutRoot">
<controls:PanoramaItem Name="sitePanoramaItem" Header="{Binding Name}">
<Controls:DockPanel VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Controls:DockPanel.Dock="Top">
<Image Source="../Images/action.png" Width="64" />
<TextBlock Text="{Binding Stats, Mode=TwoWay}" FontSize="45" Margin="15,0,0,0" />
</StackPanel>
<Grid x:Name="graphCanvas" HorizontalAlignment="Stretch" Margin="10,10,10,10"> </Grid>
</Controls:DockPanel>
</controls:PanoramaItem>
</Grid>
</UserControl>
When I click on graphCanvas what I'd like to do is sorta pop the graphCanvas out and display that fullscreen then when I click again restore it to where it was. I've been all over this site and Google and can't find anything similar to what I'm looking for.
I would still like to maintain the Panorama control functionality so that the graphCanvas is still the only one visible but you can cycle through them. Currently I have it sorta working in that I remove the Grid from the DockPanel and put it directly in the LayoutRoot while making the sitePanoramaItem collapsed. However, it's not fullscreen as the Panorama name is still visible (I guess I could hide that as well...) When I put the graphCanvas back int he DockPanel the size of the canvas is all screwed up.
I was hoping there was a simpler way.
Is it even possible?
It is possible to create the UI you describe but it's not going to be simple. You're on the right track with removing it in code and adding it the LayoutRoot and making the Panorama hidden. However you would have to code the scrolling behavior yourself and that is going to be quite tricky - especially making it feel the way to panorama does.
One trick you could try is actually layer a PivotControl on top of your Panorama and have it be collapsed by default. Also edit it's template to remove all default content eg: remove the header control, set margins to 0, etc). Then when you want to go full screen you can remove all the graphCanvases from the Panorama items and and add them to new PivotItems in the PivotControl. Then hide the Panorama and show the Pivot. This will give you scrolling capability for free and the illusion of full screen.
Having said all that I'm not sure I would recommend this. The more common approach would be to simply be to navigate to another page when the user selects an item and handle the full screen aspects there (possibly using the Pivot control again for scrolling). And when you want to leave "fullscreen" mode simply navigate back to the first page. Handling Tombstoning of the fullscreen state will be much easier with this approach for one thing.
You can try making the graphCanvas a Page and putting it in a different XAML. Then add a frame (name it InnerFrame for example) in the same place where you have the graphCanvas right now and navigate to that page with InnerFrame. When the frame is clicked, you navigate with the RootFrame of the app to your graphCanvas page. When you decide to close it, just navigate back with the RootFrame.
Hope it's clear enough :)
Edit:
Navigation in WP7 works very similar as the standard navigation in Silverlight 4, but it's a bit more restrictive. Just throw a PhoneApplicationFrame in your XAML like this:
<phone:PhoneApplicationFrame x:Name="Frame" />
This is basically the same as a Silverlight frame. All the pages you create inherit from PhoneApplicationPage by default, so they can be showed in a frame without any changes.
Your whole application actually runs on a PhoneApplicationFrame. If you take a look at your App class you will see this:
public PhoneApplicationFrame RootFrame { get; private set; }
Here's the MSDN documentation for the navigation system on WP7