WPF Ribbon UI插件式开发框架(2)-主框架

来源:互联网 发布:origin导入excel数据 编辑:程序博客网 时间:2024/04/29 22:44
接上文,说说主框架。主框架作为一个宿主,提供整个应用程序的菜单及插件展示。
  1. 框架菜单如图
    系统管理插件组
    框架菜单1
    小工具组菜单2
    框架菜单2
    类似windows开始菜单组
    工具栏菜单在所有菜单最上面
    这里写图片描述
  2. 这些菜单的配置配置文件

【.\SSHM.SmartClientOutput\ClientConfig\PlusMenu.xml】

<?xml version="1.0" encoding="utf-8"?><root>  <appMenu>    <plus text="关闭" tooltip="关闭系统"          type="CusFunc" img="./Images/Exit.png">      <dllPath>.\SSHM.PlusFunc\SSHM.PlusFunc.dll</dllPath>      <clsName>SSHM.PlusFunc.FuncHelper</clsName>      <funcName>CloseApplication</funcName>    </plus>  </appMenu>  <quickAccess>    <plus text="关闭" tooltip="关闭系统"          type="CusFunc" img="./Images/Exit.png">      <dllPath>.\SSHM.PlusFunc\SSHM.PlusFunc.dll</dllPath>      <clsName>SSHM.PlusFunc.FuncHelper</clsName>      <funcName>CloseApplication</funcName>    </plus>  </quickAccess>  <tab text="系统管理" tooltip="系统管理">    <group text="系统管理" tooltip="系统管理">      <plus text="插件管理" tooltip="插件管理"            type="UI" img="./Images/PlusIn.png">        <dllPath>.\SSHM.PlusMrg\SSHM.PlusMrg.dll</dllPath>        <clsName>SSHM.PlusMrg.Views.UCPlusMainMrg</clsName>        <position>DocumentHost</position>      </plus>      <plus text="日志查看" tooltip="日志查看"            type="UI" img="./Images/Log.png">        <dllPath>.\SSHM.LogPlus\SSHM.LogPlus.dll</dllPath>        <clsName>SSHM.LogPlus.Views.UCLog</clsName>        <position>DockedBottom</position>      </plus>      <plus text="主题切换" tooltip="主题切换"            type="UI" img="./Images/PlusIn.png">        <dllPath>.\SSHM.ThemingMrg\SSHM.ThemingMrg.dll</dllPath>        <clsName>SSHM.ThemingMrg.Views.UCThemingMrg</clsName>        <position>DockedTop</position>      </plus>      <plus text="关闭" tooltip="关闭系统"            type="CusFunc" img="./Images/Exit.png">        <dllPath>.\SSHM.PlusFunc\SSHM.PlusFunc.dll</dllPath>        <clsName>SSHM.PlusFunc.FuncHelper</clsName>        <funcName>CloseApplication</funcName>      </plus>    </group>  </tab>  <tab text="小工具" tooltip="小工具">    <group text="系统工具" tooltip="系统工具">      <plus text="记事本" tooltip="记事本"            type="WinTool" img="./Images/Notepad.png">        <toolName>notepad</toolName>      </plus>      <plus text="计算器" tooltip="计算器"            type="WinTool" img="./Images/Calc.png">        <toolName>calc</toolName>      </plus>    </group>  </tab></root><!--    plus节点下为各种type类型必需的一些节点配置    type对应的插件类型现有,        1)UI      //插件UI        2)CusFunc //自定义方法        3)WinTool //操作系统工具,如:notepad,calc      节点position对应类型有        DockedLeft        DockedBottom        DockedRight        DockedTop        FloatingDockable        FloatingOnly        DocumentHost-->

说明一下:
2.1、appMenu为开始菜单配置节点,下面可以配置多个插件,现在配置为

<appMenu>    <plus text="关闭" tooltip="关闭系统"          type="CusFunc" img="./Images/Exit.png">      <dllPath>.\SSHM.PlusFunc\SSHM.PlusFunc.dll</dllPath>      <clsName>SSHM.PlusFunc.FuncHelper</clsName>      <funcName>CloseApplication</funcName>    </plus>  </appMenu>

只配置了一个关闭插件,点击该插件时,在主框架中调用动态库dllPath(.\SSHM.PlusFunc\SSHM.PlusFunc.dll)中类clsName(SSHM.PlusFunc.FuncHelper)的方法CloseApplication
2.2、工具栏菜单(quickAccess)同开始菜单一样,配置类似
2.3、tab组有系统管理和小工具
2.3.1、系统管理组有分了一个group(系统管理)组,有插件管理、日志查看、主题切换、关闭,前三个主框架会加载对应动态库的UI插件,显示在下面的工作区中,上一篇有图,关闭和开始菜单、工具栏菜单一样
2.3.2、小工具组分了一个系统工具组,框架会调用windows的记事本(notepad)、计算器(calc)等,配置都比较简单

  1. 菜单展示xaml代码(SSHM.SmartClient\Views\MainRibbonWindow.xaml)
<telerik:RadRibbonWindow x:Class="SSHM.SmartClient.Views.MainRibbonWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"                         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"              xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"                          xmlns:local="clr-namespace:SSHM.SmartClient.Views"                         xmlns:com="clr-namespace:SSHM.SmartClient.Common"                         telerik:StyleManager.Theme="{Binding ApplicationTheme}"                         WindowState="Maximized"                         Icon="{Binding AppConfig.SysIcon}">    <i:Interaction.Triggers>        <i:EventTrigger EventName="Closing">            <ei:CallMethodAction MethodName="RadRibbonWindow_Closing"                                                  TargetObject="{Binding}"/>        </i:EventTrigger>    </i:Interaction.Triggers>    <telerik:RadBusyIndicator Grid.RowSpan="3" BusyContent="{Binding BusyContent}" IsBusy="{Binding IsBusy}">        <Grid Name="rootGrid">            <Grid.RowDefinitions>                <RowDefinition Height="Auto"/>                <RowDefinition Height="*"/>                <RowDefinition Height="Auto"/>            </Grid.RowDefinitions>            <Grid.Resources>                <!--开始菜单模板-->                <DataTemplate x:Key="sysMenuTemplate">                    <telerik:RadRibbonBackstageItem Header="{Binding Text}" IsSelectable="False" Icon="{Binding Image}">                        <i:Interaction.Triggers>                            <i:EventTrigger EventName="Click">                                <ei:CallMethodAction MethodName="ExecuteMenuCommandHandler"                                                  TargetObject="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadRibbonWindow},Path=DataContext}"/>                            </i:EventTrigger>                        </i:Interaction.Triggers>                    </telerik:RadRibbonBackstageItem>                </DataTemplate>                <!--通用菜单的按钮模板-->                <DataTemplate x:Key="ComMenuItemTemplate">                    <telerik:RadRibbonButton Text="{Binding Text}"                                          ToolTip="{Binding ToolTip}"                                         SmallImage="{Binding Image}"                                          LargeImage="{Binding Image}"                                         Size="{Binding ButtonSize}">                        <i:Interaction.Triggers>                            <i:EventTrigger EventName="Click">                                <ei:CallMethodAction MethodName="ExecuteMenuCommandHandler"                                                  TargetObject="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadRibbonWindow},Path=DataContext}"/>                            </i:EventTrigger>                        </i:Interaction.Triggers>                    </telerik:RadRibbonButton>                </DataTemplate>                <!--一般菜单的组模板选择器-->                <com:RibbonMenuItemTemplateSelector x:Key="GroupSelector" Buttons="{StaticResource ComMenuItemTemplate}"/>                <!--一般菜单的Group模板-->                <com:HierarchicalDataTemplate x:Key="GroupHeaderTemplate"                                          ItemsSource="{Binding ListItems}"                                            ItemTemplateSelector="{StaticResource ResourceKey=GroupSelector}">                    <TextBlock Text="{Binding Text}"/>                </com:HierarchicalDataTemplate>                <!--一般菜单的Tab模板-->                <com:HierarchicalDataTemplate x:Key="TabTemplate"                                          ItemsSource="{Binding ListItems}"                                            ItemTemplate="{StaticResource ResourceKey=GroupHeaderTemplate}">                    <TextBlock Text="{Binding Text}"/>                </com:HierarchicalDataTemplate>            </Grid.Resources>            <!--菜单-->            <telerik:RadRibbonView x:Name="ribbonView"                                HelpButtonVisibility="Visible"                               ApplicationName="{Binding AppConfig.AppName}"                                ItemsSource="{Binding PlusMenuViewModel.ListTabMenus}"                               ItemTemplate="{StaticResource ResourceKey=TabTemplate}"                               ApplicationButtonContent="{Binding AppConfig.AppMenuName}"                                BackstageClippingElement="{Binding ElementName=rootGrid}"                               Title="{Binding AppConfig.Title}"                                IsBackstageOpen="{Binding IsBackstageOpen,Mode=TwoWay}"                               SelectedItem="{Binding SelectedTab, Mode=TwoWay}"                               HelpCommand="{Binding ShowHelperCmd}"                               HelpCommandTarget="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadRibbonWindow},Path=DataContext}">                <!--系统菜单-->                <telerik:RadRibbonView.Backstage>                    <telerik:RadRibbonBackstage ItemTemplate="{StaticResource sysMenuTemplate}"                                            ItemsSource="{Binding PlusMenuViewModel.ListAppMenus}"/>                </telerik:RadRibbonView.Backstage>                <!--工具栏-->                <telerik:RadRibbonView.QuickAccessToolBar>                    <telerik:QuickAccessToolBar ItemTemplate="{StaticResource ComMenuItemTemplate}"                                             ItemsSource="{Binding PlusMenuViewModel.ListQuickAccessMenus}"/>                </telerik:RadRibbonView.QuickAccessToolBar>            </telerik:RadRibbonView>            <telerik:RadDocking x:Name="radDocking" Grid.Row="1">                <i:Interaction.Triggers>                    <!--关闭RadPane时触发-->                    <i:EventTrigger EventName="Close" SourceName="radDocking">                        <ei:CallMethodAction MethodName="RadDockingCloseCmdHandler" TargetObject="{Binding}"/>                    </i:EventTrigger>                    <!--RadPanel切换时触发-->                    <i:EventTrigger EventName="ActivePaneChanged" SourceName="radDocking">                        <ei:CallMethodAction MethodName="RadDockingActivePaneChangedHandler" TargetObject="{Binding}"/>                    </i:EventTrigger>                </i:Interaction.Triggers>            </telerik:RadDocking>            <!--状态栏-->            <StatusBar Grid.Row="2">                <StatusBarItem Content="{Binding CurrentStatus}" HorizontalAlignment="Left"/>                <StatusBarItem Content="{Binding CurrentDatetime}" HorizontalAlignment="Right"/>            </StatusBar>        </Grid>    </telerik:RadBusyIndicator></telerik:RadRibbonWindow>

这段代码中,RadRibbonView负责加载菜单,RadDocking负责加载UI插件展示,StatusBar目前只有两个Item,自己加挺方便的

该xaml对应的ViewModel为SSHM.SmartClient\ViewModels\MainViewModel,该类负责加载配置文件,定义View层需要显示的菜单有状态栏属性等

发现写个简单的博客这么不容易,都不知道自己写的什么,如果看不懂,可以看看资源源码,感觉看源码要清晰明了的多

0 0