wpf区域用法

区域主要使用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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值