区域主要使用IRegionManager接口
<Window x:Class="FullApp1.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
xmlns:core="clr-namespace:FullApp1.Core;assembly=FullApp1.Core"
Title="{Binding Title}" Height="350" Width="525" >
<Grid>
<Grid.RowDefinitions >
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Content="打开A" Width="100" Height="50" Margin="10" Command="{Binding openCommand}" CommandParameter="A"> </Button>
<Button Content="打开B" Width="100" Height="50" Margin="10" Command="{Binding openCommand}" CommandParameter="B"></Button>
</StackPanel>
<ContentControl Content ="{Binding BodyContent}" Grid.Row="1"></ContentControl>
<ContentControl prism:RegionManager.RegionName="regionone" Grid.Row="1"/>
<!--<ContentControl prism:RegionManager.RegionName="{x:Static core:RegionNames.ContentRegion}" />-->
</Grid>
</Window>
using FullApp1.Views;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
namespace FullApp1.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Application";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
private readonly IRegionManager regionManager;
public DelegateCommand<string> openCommand { get; private set; }
public MainWindowViewModel(IRegionManager regionManager)
{
openCommand = new DelegateCommand<string>(showOpen);
this.regionManager = regionManager;
}
private string bodyContent;
public string BodyContent {
get { return bodyContent; }
set {
bodyContent = value;
RaisePropertyChanged();
}
}
private void showOpen(string str)
{
if (str=="A")
{
BodyContent = "显示A";
}
if (str=="B")
{
BodyContent = "显示B";
}
regionManager.Regions["regionone"].RequestNavigate("ViewB");
}
}
}
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IMessageService, MessageService>();
containerRegistry.RegisterForNavigation<ViewB>("ViewB");
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<ModuleNameModule>();
}
}
用过控件ViewA
<UserControl x:Class="FullApp1.Views.ViewB"
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:local="clr-namespace:FullApp1.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="我的测试" FontSize="80" Foreground="Red"></TextBlock>
</Grid>
</UserControl>