WPF + DevExpress学习05 Prism +Dev DocumentGroup

  1. 首先使用 Prism 配合 DocumentGroup 根据Dev官方文档 需要在App.cs中 注册
 引入 包 DevExpress.Wpf.PrismAdapters
 protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
        {

            var factory = Container.Resolve();
            regionAdapterMappings.RegisterMapping(typeof(DocumentGroup), AdapterFactory.Make>(factory));
            base.ConfigureRegionAdapterMappings(regionAdapterMappings);
        }

  1. 界面代码MainWindows
<dx:ThemedWindow  xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
                  xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"  
                  x:Class="NhxProjectSytem.Main.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/" 
        xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion" xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
                  prism:ViewModelLocator.AutoWireViewModel="True"
        Height="800" Width="1000"
         WindowState="Maximized"
         WindowStartupLocation="CenterScreen"
         UseLayoutRounding="True" 
         
          ResizeMode="CanResizeWithGrip"
         >
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:VisualStateService/>
    dxmvvm:Interaction.Behaviors>
    <DockPanel>
   // 页面加载 绑定ViewModel PageLoding
        <dx:LoadingDecorator IsSplashScreenShown="{Binding PageLoding}"   BorderEffect="Default" SplashScreenLocation="CenterWindow"  BorderEffectColor="Blue" />
        <dxdo:DockLayoutManager FloatingMode="Desktop" ClosedPanelsBarVisibility="Never">
            <dxdo:LayoutGroup Orientation="Horizontal">
                <dxdo:LayoutPanel Name="Navigation" Caption="导航"  AllowClose="False" MinWidth="200" ItemWidth="200">
                // 菜单 绑定 EmployeeDepartments     选择菜单时绑定 ModuleInfo
                    <dxa:AccordionControl    Name="Menus"  SelectedItem="{Binding ModuleInfo}" ItemsSource="{Binding EmployeeDepartments}" ChildrenPath="Employees" >
                       // 对于渲染这个需要对 Header--> ModuleName
                        <dxa:AccordionControl.ItemContainerStyle>
                            <Style TargetType="dxa:AccordionItem">
                                "Header" Value="{Binding  ModuleName}"/>
                            Style>
                        dxa:AccordionControl.ItemContainerStyle>
                    dxa:AccordionControl>                 
                dxdo:LayoutPanel>             
                // DocumentGroup  绑定上  ContentRegion 
                <dxdo:DocumentGroup  Name="Documents"   
                                      DestroyOnClosingChildren="False"
                                      prism:RegionManager.RegionName="ContentRegion"         
                                      prism:ViewModelLocator.AutoWireViewModel="True"
                                     >
                    	// Todo 代办的一个问题 但是也是实现了 感觉方式不是太好  如果我使用  Caption 那么他绑定的是 当前页面的ViewModel  使用Content 绑定当前页面对象的属性
                    <dxdo:DocumentGroup.ItemStyle  >
                        <Style TargetType="dxdo:LayoutPanel">
                            "Caption" Value="{Binding Content.PanelCaption, RelativeSource={RelativeSource Self}}" />
                            "ClosingBehavior" Value="ImmediatelyRemove"/>
                        Style>
                    dxdo:DocumentGroup.ItemStyle>
                dxdo:DocumentGroup>
            dxdo:LayoutGroup>
            
        dxdo:DockLayoutManager>
    DockPanel>

dx:ThemedWindow>
    

3.部分界面的实现

<UserControl x:Class="BasicSetting.Views.BasicSettingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:BasicSetting.Views"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
            
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             
              Background="Red"
             >
    <Grid>

        <DatePicker x:Name="MyDatePicker" >DatePicker>
     
    Grid>
UserControl>

 public partial class BasicSettingView : UserControl
    {
        public BasicSettingView()
        {
            InitializeComponent();
        }
        public string PanelCaption { get { return "基础设置"; } }
    }
namespace BasicSetting
{

    [Module(ModuleName = "BasicSettingView")]
    public class BasicSettingModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            var regionManager = containerProvider.Resolve<IRegionManager>();
           
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<BasicSettingView,BasicSettingViewModel>();
          
        }
    }
}

你可能感兴趣的:(WPF,wpf,学习,ui)