Back to Devexpress

FrameNavigationService.Frame Property

wpf-devexpress-dot-xpf-dot-windowsui-dot-navigation-dot-framenavigationservice.md

latest9.9 KB
Original Source

FrameNavigationService.Frame Property

Gets or sets the Frame to which the current service is associated.

Namespace : DevExpress.Xpf.WindowsUI.Navigation

Assembly : DevExpress.Xpf.Controls.v25.2.dll

NuGet Package : DevExpress.Wpf.Controls

Declaration

csharp
public NavigationFrame Frame { get; set; }
vb
Public Property Frame As NavigationFrame

Property Value

TypeDescription
NavigationFrame

A NavigationFrame object to which the current service is associated.

|

Remarks

You need to set the Frame property to the NavigationFrame object that contains Views to navigate between. Otherwise, the methods provided by the FrameNavigationService will not work.

Example

The FrameNavigationService provides methods to navigate between Views within a NavigationFrame. This example shows how to use this service. In this example, the MainWindow contains a NavigationFrame, which shows a HomeView at startup. The HomeView contains a Tile, which invokes a command to navigate to a DetailView when clicked. The DetailView contains the Back button for backward navigation.

View Example

xaml
<UserControl x:Class="DXSample.View.MainView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui"
    xmlns:dxwuin="http://schemas.devexpress.com/winfx/2008/xaml/windowsui/navigation"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
    xmlns:ViewModel="clr-namespace:DXSample.ViewModel" 
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" 
    DataContext="{dxmvvm:ViewModelSource Type={x:Type ViewModel:MainViewModel}}">
    <Grid>
        <dxwui:NavigationFrame AnimationType="SlideHorizontal" NavigationCacheMode="Required">
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="Loaded" Command="{Binding OnViewLoadedCommand}" />
                <dxwuin:FrameNavigationService />
            </dxmvvm:Interaction.Behaviors>
        </dxwui:NavigationFrame>
    </Grid>
</UserControl>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;

namespace DXSample.ViewModel {
    public class MainViewModel {
        private INavigationService NavigationService { get { return this.GetService<INavigationService>(); } }

        public MainViewModel() { }

        public void OnViewLoaded() {
            NavigationService.Navigate("HomeView", null, this);
        }
    }
}
xaml
<UserControl x:Class="DXSample.View.HomeView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" 
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
    xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui"
    xmlns:ViewModel="clr-namespace:DXSample.ViewModel" 
    DataContext="{dxmvvm:ViewModelSource Type={x:Type ViewModel:HomeViewModel}}">
        <dxwui:PageAdornerControl Header="Home View">
            <lc:TileLayoutControl>
                <lc:Tile Size="Small" Command="{Binding NavigateDetailsCommand}">
                    <TextBlock Text="Details" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </lc:Tile>
            </lc:TileLayoutControl>
        </dxwui:PageAdornerControl>
</UserControl>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;

namespace DXSample.ViewModel {
    public class DetailViewModel {
        private INavigationService NavigationService { get { return this.GetService<INavigationService>(); } }
        public void NavigateNextDetail() {
            NavigationService.Navigate("NextDetailView", null, this);
        }
        public void NavigateBack() {
            NavigationService.GoBack();
        }
        public bool CanNavigateBack() {
            return NavigationService.CanGoBack;
        }
        public void NavigateForward() {
            NavigationService.GoForward();
        }
        public bool CanNavigateForward() {
            return NavigationService != null && NavigationService.CanGoForward;
        }
    }
}
xaml
<UserControl x:Class="DXSample.View.DetailView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui"
    xmlns:dxwuii="http://schemas.devexpress.com/winfx/2008/xaml/windowsui/internal"
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
    xmlns:ViewModel="clr-namespace:DXSample.ViewModel" 
    DataContext="{dxmvvm:ViewModelSource Type={x:Type ViewModel:DetailViewModel}}">
    <Grid>
        <dxwui:PageAdornerControl Header="Detail View">
            <dxwui:PageAdornerControl.HeaderTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding}" />
                        <Button Grid.Column="1" Content="Go Forward" HorizontalAlignment="Right" FontSize="14" Command="{Binding DataContext.NavigateForwardCommand, RelativeSource={RelativeSource AncestorType=dxwuii:NavigationHeaderControl}}" />
                    </Grid>
                </DataTemplate>
            </dxwui:PageAdornerControl.HeaderTemplate>
            <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Next Detail View" Padding="4" Margin="2" Command="{Binding NavigateNextDetailCommand}"/>
        </dxwui:PageAdornerControl>
    </Grid>
</UserControl>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;

namespace DXSample.ViewModel {
    public class HomeViewModel {
        private INavigationService NavigationService { get { return this.GetService<INavigationService>(); } }

        public HomeViewModel() { }

        public void NavigateDetails() {
            NavigationService.Navigate("DetailView", null, this);
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO

Namespace DXSample.ViewModel
    Public Class HomeViewModel
        Private ReadOnly Property NavigationService() As INavigationService
            Get
                Return Me.GetService(Of INavigationService)()
            End Get
        End Property

        Public Sub New()
        End Sub

        Public Sub NavigateDetails()
            NavigationService.Navigate("DetailView", Nothing, Me)
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO

Namespace DXSample.ViewModel
    Public Class MainViewModel
        Private ReadOnly Property NavigationService() As INavigationService
            Get
                Return Me.GetService(Of INavigationService)()
            End Get
        End Property

        Public Sub New()
        End Sub

        Public Sub OnViewLoaded()
            NavigationService.Navigate("HomeView", Nothing, Me)
        End Sub
    End Class
End Namespace
vb
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO

Namespace DXSample.ViewModel
    Public Class DetailViewModel
        Private ReadOnly Property NavigationService() As INavigationService
            Get
                Return Me.GetService(Of INavigationService)()
            End Get
        End Property
        Public Sub NavigateNextDetail()
            NavigationService.Navigate("NextDetailView", Nothing, Me)
        End Sub
        Public Sub NavigateBack()
            NavigationService.GoBack()
        End Sub
        Public Function CanNavigateBack() As Boolean
            Return NavigationService.CanGoBack
        End Function
        Public Sub NavigateForward()
            NavigationService.GoForward()
        End Sub
        Public Function CanNavigateForward() As Boolean
            Return NavigationService IsNot Nothing AndAlso NavigationService.CanGoForward
        End Function
    End Class
End Namespace

See Also

FrameNavigationService Class

FrameNavigationService Members

DevExpress.Xpf.WindowsUI.Navigation Namespace