首页 > 编程语言 >PDMS & AM 侧边栏菜单 C# WPF技术

PDMS & AM 侧边栏菜单 C# WPF技术

时间:2023-10-28 19:11:44浏览次数:43  
标签:mywin PDMS C# AM System using var new public

项目的完整下载地址

https://files.cnblogs.com/files/NanShengBlogs/AMCSTest.zip?t=1698491030&download=true

先看效果

 

下面先看实现的几个函数

1# 创建wpf的用户控件,无选项的参考此链接修改csproject文件

类库项目添加wpf方法

写入下列代码

<UserControl x:Class="AMCSTest.UserControl1"
             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:AMCSTest"
             mc:Ignorable="d" 
                     MinWidth="85"  MinHeight="250" Background="#BFDBFF" >
    <UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="Expander.StackPanel.Style" TargetType="FrameworkElement">
                <Setter Property="HorizontalAlignment" Value="Center"></Setter>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid >
        <ItemsControl ItemsSource="{Binding Dict}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Expander   IsExpanded="False" Background="Transparent" FontWeight="Bold" IsEnabled="True" Foreground="Black" SnapsToDevicePixels="True" BorderBrush="Black" BorderThickness="0.8" Margin=" 0,2,0,2">
                        <Expander.Header>
                            <TextBlock Text="{Binding Path=Key}" TextWrapping="Wrap" FontWeight="ExtraBold" FontSize="12"/>
                        </Expander.Header>
                        <ScrollViewer VerticalScrollBarVisibility="Hidden" MaxHeight="300"  >
                            <StackPanel  HorizontalAlignment="Stretch" Margin=" 0,2,0,2" Orientation="Vertical">
                                <ItemsControl ItemsSource="{Binding Path=Value }">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Button Style="{StaticResource Expander.StackPanel.Style}"  Tag="{Binding Path=Value}" Click="Button_Click" HorizontalAlignment="Stretch" Margin="0,1,0,1" Background="Transparent" Foreground="Black" FontStyle="Normal" FontWeight="Regular">
                                                <TextBlock Text="{Binding Path=Key}" TextWrapping="Wrap" FontSize="12">
                                                </TextBlock>
                                            </Button>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </StackPanel>
                        </ScrollViewer>
                    </Expander>
                    <!--<Button Content="{Binding Path=Key}" Tag="{Binding Path=Value}"
                 Click="Button_Click"  HorizontalAlignment="Stretch" Margin="0,1,0,1" Background="#FF1EB856" BorderBrush="#FF64D126" Grid.IsSharedSizeScope="False"/>-->
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>

usercontrol的交互代码

/// <summary>
/// UserControl1.xaml 的交互逻辑
/// </summary>
public partial class UserControl1 : UserControl
{
    public Command Cmd { get; set; }
    public WindowManager WinManager { get; set; }
    public UserControl1(WindowManager wm, Command _cmd)
    {
        InitializeComponent();
        this.WinManager = wm;
        this.Cmd = _cmd;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var btn = sender as Button;
        var mi = btn.Tag as MethodInfo;
        if (mi.DeclaringType == null) return;
        try
        {
            mi.Invoke(
           mi.IsStatic ? null : Activator.CreateInstance(mi.DeclaringType),
           new object[] { WinManager});
        }
        catch (Exception ex)
        {
            Interaction.MsgBox(ex.StackTrace);
        }   
    }
}

框架代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

//引用AM的dll文件,在AM的安装目录下面

using Aveva.ApplicationFramework;
using Aveva.ApplicationFramework.Presentation;

using Microsoft.VisualBasic;

namespace AMCSTest
{
    public class MianClass : IAddin
    {
        public string Description => base.GetType().FullName;
        public string Name => base.GetType().FullName;
        public void Start(ServiceManager serviceManager)
        {
            var winManager = serviceManager.GetService(typeof(WindowManager)) as WindowManager;
            结构工具 dwcmd = new 结构工具(winManager);
           // var cmdmanager = serviceManager.GetService(typeof(CommandManager)) as CommandManager;
           //cmdmanager?.Commands.Add(dwcmd);
            var cbm = serviceManager.GetService(typeof(CommandBarManager)) as CommandBarManager;
            cbm.AllowCustomization = true;
            cbm.BeginUpdate();
            var cbar = cbm.CommandBars.AddCommandBar(typeof(结构工具).Name);//typeof(结构工具).Name
            cbar.DockedPosition = DockedPosition.Top;
            cbar.AllowHiding = false;
            cbar.AllowFloating = true;
            var assemblyDate = System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString("yyyy年MM月dd日-HH点mm分");
            cbar.Caption = cbar.Key + $",软件版本({assemblyDate})";

            var cur002 = cbm.RootTools.AddButtonTool(nameof(结构工具), nameof(结构工具), null, dwcmd);
            var btl2 = cbar.Tools.AddTool(nameof(结构工具)) as ButtonTool;
            cbm.EndUpdate(true);
            cbm.SaveLayout();

        }

        public void Stop()
        {
        }
        public static Dictionary<string, Dictionary<string,MethodInfo>> GetAllCommand()
        {
            Dictionary<string, Dictionary<string, MethodInfo>> dicts = new Dictionary<string, Dictionary<string, MethodInfo>>();
            List<Type> allClass = Assembly.GetExecutingAssembly().GetTypes().Where(a => a.IsClass && a.IsPublic).ToList<Type>();
            List<MyAMFunction> mis = new List<MyAMFunction>();
            foreach (Type item in allClass)
            {
                List<MethodInfo> curClsMis = item.GetMethods().Where(m => m.GetCustomAttributes(typeof(MyAmFunctionAtt), true).Any()).ToList<MethodInfo>();
                if (curClsMis.Count > 0)
                {
                    foreach (MethodInfo mi in curClsMis)
                    {
                        mis.Add(new MyAMFunction(mi));
                    }
                }
            }

            Dictionary<string, Dictionary<string, MethodInfo>> GetAllCommand;
            if (mis.Count == 0)
                GetAllCommand = dicts;
            else
            {
                foreach (MyAMFunction item2 in mis)
                {
                    Dictionary<string, MethodInfo> temp = new Dictionary<string, MethodInfo>();
                    if (dicts.ContainsKey(item2.Att.MenuName))
                    {
                        temp = dicts[item2.Att.MenuName];
                    }
                    temp.Add(item2.Att.FunctionName, item2.Method);
                    dicts[item2.Att.MenuName] = temp;
                }
                GetAllCommand = dicts;
            }
            return GetAllCommand;
        }
    }
    public class MyAMFunction
    {
        public MyAmFunctionAtt Att { get; set; }
        public MethodInfo Method { get; set; }
        public MyAMFunction(MethodInfo mi)
        {
            this.Att = (MyAmFunctionAtt)mi.GetCustomAttributes(true).First(a => a.GetType().FullName == typeof(MyAmFunctionAtt).FullName);
            this.Method = mi;
        }
    }

    public class MyAmFunctionAtt : Attribute
    {
        public string MenuName { get; set; }
        public string FunctionName { get; set; }
        public MyAmFunctionAtt(string _menuNam, string _functionName)
        {
            this.MenuName = _menuNam;
            this.FunctionName = _functionName;
        }
    }


    public class 结构工具 : Command
    {
        private DockedWindow _mywin;

        public 结构工具(WindowManager wm)
        {
            base.Key = this.GetType().FullName;
            var con = new UserControl1(wm, this);
            AmCommand cmds = new AmCommand
            {
                Dict = MianClass.GetAllCommand()
            };
            con.DataContext = cmds;
            var eh = new ElementHost()
            {
                Child = con,
                AutoSize = true,
                Dock = DockStyle.Fill
            };
            _mywin = wm.CreateDockedWindow("xxxx", $"xxxx", eh, DockedPosition.Right);
            _mywin.MaximumSize = new System.Drawing.Size(185, 850);
            _mywin.MinimumSize = new System.Drawing.Size(135, 850);
            _mywin.DockGroupStyle = DockGroupStyle.TabGroup;
            _mywin.SaveLayout = true;
            wm.WindowLayoutLoaded += (s, e) => this.Checked = false;
            _mywin.Closed += (s, e) => this.Checked = _mywin.Visible;
            this.ExecuteOnCheckedChange = false;
        }

        public class AmCommand
        {
            public Dictionary<string, Dictionary<string, MethodInfo>> Dict { get; set; } = new Dictionary<string, Dictionary<string, MethodInfo>>();
            public AmCommand() { }
        }
        public override void Execute()
        {
            try
            {
                if (_mywin.Visible) _mywin.Hide(); else _mywin.Show();
                base.Execute();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.StackTrace);
            }
        }
    }
}

 

标签:mywin,PDMS,C#,AM,System,using,var,new,public
From: https://www.cnblogs.com/NanShengBlogs/p/17794482.html

相关文章

  • JavaFrame
    1.课程回顾在本人大三时修了JavaWeb编程和Java框架编程,这两门的课程结构大致是这样:JavaWeb:Java框架:Web开发基础Maven工具Servlet基础Spring框架ServletAPI核心接口SpringMVC会话跟踪数据持久化技术数据访问与JavaBeanBootstrap,Javascript,Iframe,Ajax......
  • Proxy Facade 设计模式运行时的工作原理介绍
    ProxyFacade设计模式是一个强大的工具,它可以帮助我们创建一个简单的代理外观类,以便根据方法和属性的配置来访问系统的各种功能。在这篇文章中,我们将深入探讨ProxyFacade模式的运行时工作原理,并提供一些实际示例来帮助您更好地理解。什么是ProxyFacade设计模式?ProxyFaca......
  • Wi-Fi 5(802.11ac)概要介绍
    Wi-Fi5(802.11ac)技术深刻改变了无线通信的格局,带来了更快的速度、更大的容量和更可靠的连接。在本文中,我将探讨Wi-Fi5技术的核心概念,如多用户多输入多输出(MU-MIMO)、波束成形(Beamforming)等,并提供实际示例来说明这些概念的工作原理。第一部分:Wi-Fi5的基础概念1.1Wi-Fi5的背景......
  • C语言入门之数组之一维和二维----小白
    今天的介绍C语言数组的概念。数组的分类一维数组和多维数组。一维数组和二维数组,这是我们今天主要介绍的两种。一数组的概念。数组是一组相同类型元素的集合,我们在前面介绍了数据类型。他可以将多个相同类型的数据,放到一起。1.数组的数据不能为0,至少要放一个元素。或者对他进行初始......
  • 无涯教程-Clojure - defstruct函数
    该函数用于定义所需的结构。defstruct-语法(defstructstructnamekeys)参数   - "structname"是要赋予结构的名称,"keys"是需要作为结构一部分的键。返回值 - 返回结构对象。defstruct-示例以下程序显示了有关如何使用它的示例。(nsclojure.examples.......
  • Commands and Queries 设计模式详解
    在Angular应用开发领域,CommandsandQueries设计模式是一个关键的概念,它有助于有效地管理应用程序的状态和与后端的交互。本文将深入探讨这一设计模式的核心要点,并通过实际示例来加以说明。基本概念命令(Commands)命令代表了一项能够改变系统状态的操作,通常通过向后端发起RES......
  • 关于 Storefront Site Context 的概念介绍
    电商平台中Site模型的详细介绍在电商平台开发中,Site(网站)模型是一个至关重要的概念,它在内容管理系统(CMS)中扮演着关键角色。每个在CMS中定义的网站都拥有其自身的上下文,这个上下文包括基本网站ID、语言属性和货币属性。此外,上下文还定义了如何在URL中持久化这些属性。通过在spart......
  • 【ArcPy】Python工具的参数校验
    在updateMessages方法中检查输入图层数据源的工作空间是否是本地数据,如果不是,设置错误。在updateParameters方法中从图层派生出第4个参数,即输出要素类的路径。注意该参数的类型需要是“派生(Derived)”importarcpyclassToolValidator(object):"""Classforvalidatingatoo......
  • netty同时支持tcp和websocket
    最近接手了别人的netty框架实现的im的一个项目,基于tcp实现通信,但是领导要求做一个网页版的聊天,接入到目前的系统,由于第一次接触这种项目,百度一圈大部分都是通过websocket实现通信的方式,最后通过chatgpt发现确实可以同时支持tcp和websocket,现在把方式放上Netty是一个高性能、异步事......
  • CSP-J 2023 题解
    CSP-J2023题解T1小苹果这个题直接遍历枚举必定TLE,这是CCF的出题风格,每题T1巨水无比,但是往往又需要一些思维。这道题我们可以发现每一轮操作都会拿走\(1+(n-1)/3\)个苹果,所以每次让\(n\)减去\(1+(n-1)/3\)就可以了。然后记录编号为\(n\)什么时候拿......