#

 

 

 

WinUI3 NavigationView

Mit dem NavigationView schaltet man Tabs in Windows Applicatons um.

 

Ein Bild, das Text enthält.
Automatisch generierte Beschreibung

 

 

 

Dabei werden Windows Page Elemente in den ContentFrame geladen

 

Ein Bild, das Text enthält.
Automatisch generierte Beschreibung

 

 

 

MainWindow.xaml

<Window

    x:Class="Downloader_WebBackups.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:Downloader_WebBackups"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d">

 

    <Grid>

       

        <Grid.RowDefinitions>

            <RowDefinition Height="32"/>

            <RowDefinition/>

        </Grid.RowDefinitions>

        <!--Titlebar-->

        <Grid x:Name="AppTitleBar">

            <Image Source="Assets/Square44x44Logo.targetsize-16.png"

                   HorizontalAlignment="Left"

                   Width="16" Height="16"

                   Margin="8,0"/>

            <TextBlock x:Name="AppTitleTextBlock" Text="Downloader WebBackups"

                       TextWrapping="NoWrap"

                       Style="{StaticResource CaptionTextBlockStyle}"

                       VerticalAlignment="Center"

                       Margin="28,0,0,0"/>

        </Grid>

        <!--/Titlebar-->

 

        <NavigationView x:Name="navView" PaneDisplayMode="Top"    SelectionFollowsFocus="Enabled" IsBackButtonVisible="Collapsed"

        Grid.Row="1"    SelectionChanged="navView_SelectionChanged"

        >

            <NavigationView.MenuItems>

                <NavigationViewItem Icon="Download" Content="Download" x:Name="NavItem_Download" />

                <NavigationViewItem Icon="Setting" Content="Folders" x:Name="NavItem_Folders" />

               

            </NavigationView.MenuItems>

            <Frame x:Name="contentFrame"/>

       

            <!--Content-->

 

            <!--Content-->

        </NavigationView>

    </Grid>

</Window>

 

 

MainWindow.cs

 

using Microsoft.UI.Xaml;

using Microsoft.UI.Xaml.Controls;

using Microsoft.UI.Xaml.Navigation;

using System;

 

// To learn more about WinUI, the WinUI project structure,

// and more about our project templates, see: http://aka.ms/winui-project-info.

 

namespace Downloader_WebBackups

{

    /// <summary>

    /// An empty window that can be used on its own or navigated to within a Frame.

    /// </summary>

    public sealed partial class MainWindow : Window

    {

        public MainWindow()

        {

            this.InitializeComponent();

 

            //--< set App Title Bar >--

            //*load XAML-code from mainwindow.xaml file

            ExtendsContentIntoTitleBar = true;

            SetTitleBar(AppTitleBar);

            //--</ set App Title Bar >--

        }

 

        //C# code behind

   

        private void navView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)

        {

            FrameNavigationOptions navOptions = new FrameNavigationOptions();

            navOptions.TransitionInfoOverride = args.RecommendedNavigationTransitionInfo;

            if (sender.PaneDisplayMode == NavigationViewPaneDisplayMode.Top)

            {

                navOptions.IsNavigationStackEnabled = false;

            }

            Type pageType = typeof(Page_Download); //init

 

            var selectedItem= (NavigationViewItem)args.SelectedItem;

            if (selectedItem.Name == NavItem_Download.Name)

            {

                pageType = typeof(Page_Download);

            }

            else if (selectedItem.Name == NavItem_Folders.Name)

            {

                pageType = typeof(Page_Folders);

            }

 

 

            _ = contentFrame.Navigate(pageType);// .NavigateToType(pageType, null, navOptions);

        }

    }

    }

 

 

 

 

Page1

<!-- Copyright (c) Microsoft Corporation and Contributors. -->

<!-- Licensed under the MIT License. -->

 

<Page

    x:Class="Downloader_WebBackups.Page_Download"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:Downloader_WebBackups"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

 

    <Grid>

        <StackPanel Orientation="Vertical">

            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top">

                <Button x:Name="btnStartDownload" Click="btnStartDownload_Click" Background="LightGray" Foreground="Blue">Start Download</Button>

                <TextBlock x:Name="ctlLog" Height="600" ></TextBlock>

            </StackPanel>

            <StackPanel Orientation="Vertical" Height="40px">

                <ProgressBar x:Name="ctlProgressDirectory" Foreground="Red" Height="10px"></ProgressBar>

                <ProgressBar x:Name="ctlProgressFile" Height="10px"></ProgressBar>

                <TextBlock x:Name="ctlFilename"></TextBlock>

            </StackPanel>

        </StackPanel>

    </Grid>

</Page>

 

 

Page2

<!-- Copyright (c) Microsoft Corporation and Contributors. -->

<!-- Licensed under the MIT License. -->

 

<Page

    x:Class="Downloader_WebBackups.Page_Folders"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:Downloader_WebBackups"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

 

    <Grid>

        <TextBlock>FolderSettings</TextBlock>

       

    </Grid>

</Page>

 

 

 

 

Code

Description

CS1061

'NavigationViewItemInvokedEventArgs' does not contain a definition for 'SelectedItem' and no accessible extension method 'SelectedItem' accepting a first argument of type 'NavigationViewItemInvokedEventArgs' could be found (are you missing a using directive or an assembly reference?)

 

Mobile

.

soap2day