首页 > 其他分享 >wpf Interaction Triggers 绑定任意方法、任意Command

wpf Interaction Triggers 绑定任意方法、任意Command

时间:2023-10-27 09:56:31浏览次数:33  
标签:xmlns http Triggers com xaml System fileName Interaction 任意

 framework版本引入命名空间

  通过在代码中引入System.Windows.Interactivity.dll,引入了这个dll后我们就能够使用这个里面的方法来将事件映射到ViewModel层了,我们来看看具体的使用步骤,第一步就是引入命名控件

 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

另外还可以通过另外一种方式来引入命名空间 是一样的。

 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

 

.net版本引入命名空间 

安装 Microsoft.Xaml.Behaviors.Wpf 包

 xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

 

1、绑定任意方法

xaml设置:

xaml顶部:

      xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

      prism:ViewModelLocator.AutoWireViewModel="True"

      xmlns:prism="http://prismlibrary.com/"

 xaml设置Interaction:

   <Grid  AllowDrop="True">
       <i:Interaction.Triggers>
           <i:EventTrigger EventName="Drop">
               <i:CallMethodAction  TargetObject="{Binding}"  MethodName="Grid_Drop" ></i:CallMethodAction>
           </i:EventTrigger>
       </i:Interaction.Triggers>
 </Grid>

 

 viewmodel设置方法,传递参数:

        public  void Grid_Drop(object sender, DragEventArgs e)
        {
            try
            {
                var res = e.Data.GetData(DataFormats.FileDrop);
                string[] fileNames = ((string[])res);
                if (fileNames == null || fileNames.Count() == 0)
                {
                    return;
                }
                foreach (string fileName in fileNames)
                {
                    if (!fileName.EndsWith("acd"))
                    {
                        continue;
                    }
                    if (!File.Exists(fileName))
                    {
                        return;
                    }

                    SetMainTabItemView(fileName);
                }
            }
            catch (System.Exception)
            {
            }
        }

 

2、绑定vm中任意 command

xaml顶部:

      xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

      prism:ViewModelLocator.AutoWireViewModel="True"

      xmlns:prism="http://prismlibrary.com/"

 

xaml设置Interaction:

    <Grid  AllowDrop="True">
    
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Drop">
                <i:InvokeCommandAction Command="{Binding Grid_DropCommand}"  CommandParameter="{Binding}" ></i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Grid>

viewmodel command设置:

  public ICommand Grid_DropCommand => new DelegateCommand<object>(ExecuteGrid_DropCommand);

  private void ExecuteGrid_DropCommand(object obj)
  {
      Debug.WriteLine(obj);
  }

 

 

标签:xmlns,http,Triggers,com,xaml,System,fileName,Interaction,任意
From: https://www.cnblogs.com/JohnnyLei/p/17791069.html

相关文章

  • 2023ACMMM_Mutual Information-driven Triple Interaction Network for Efficient Ima
    一.Motivation之前网络存在的缺点:1.使用的有限的频域信息 2. 不充足的信息交互:(1)第一阶段的输出直接作为第二阶段的输入,忽略了中间特征从早期到后期的传播(2)在编码器解码器结构同尺度之间进行特征融合,忽略了阶段内和跨阶段的跨尺度信息交换3. 严重的特征......
  • 二进制转任意进制
    #include<bits/stdc++.h>usingnamespacestd;charA[16]={'1','2','3','4','5','6','7','8','9','A','B','C','D','E......
  • WPF触发器(Triggers):介绍与用法实例
    引言WindowsPresentationFoundation(WPF)提供了一个丰富和灵活的图形渲染框架,触发器(Triggers)是其中一个重要的功能。触发器能够用来控制或改变UI元素的属性、样式、甚至行为。在这篇博客文章中,我们将详细介绍WPF中触发器的种类、用法,并通过一些实际例子进行讲解。1.触发器的种......
  • 泛微E-Office协同管理系统存在任意文件读取漏洞CNVD-2022-07603
    漏洞描述泛微e-office是一款由泛微网络科技股份有限公司开发的办公自动化(OfficeAutomation,简称OA)系统。它是一种基于Web的协同办公平台,可以帮助企业实现电子化、自动化、智能化的办公环境。泛微e-officeofficeserver2.php文件存在任意文件读取漏洞,攻击者可利用该漏洞读取服务......
  • 泛微emessage管理界面存在任意文件读取漏洞2023
    漏洞简介泛微emessage管理界面存在任意文件读取漏洞隐患,攻击者可通过此漏洞获取敏感信息,为下一步攻击做准备。漏洞复现fofa语法:icon_hash="-1477694668"登录页面如下:POC:POST/HTTP/1.1Host:User-Agent:Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.......
  • 泛微E-Bridge saveYZJFile任意文件读取漏洞
    漏洞描述泛微云桥e-Bridge存在任意文件读取漏洞,攻击者成功利用该漏洞,可实现任意文件读取,获取敏感信息。漏洞复现fofa语法:app="泛微云桥e-Bridge"登录页面如下:windows系统POC:/wxjsapi/saveYZJFile?fileName=test&downloadUrl=file:///C://windows/win.ini&fileExt=txtLinux......
  • 畅捷通T+任意文件上传(CNVD-2022-60632 )漏洞复现
    一、漏洞描述022年8月29日和8月30日,畅捷通公司紧急发布安全补丁修复了畅捷通T+软件任意文件上传漏洞。未经身份认证的攻击者利用该漏洞,通过绕过系统鉴权,在特定配置环境下实现任意文件的上传,从而执行任意代码,获得服务器控制权限。目前,已有用户被不法分子利用该漏洞进行勒索病毒攻......
  • 【福利】基于matlab生成任意多面体有界 Voronoi 图附完整代码
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • 图形学、02 推导证明 | 任意一点经过透视投影后 z 坐标相对于之前有什么变化
    齐次坐标知识点:\(\begin{bmatrix}x\\y\\z\\1\\\end{bmatrix}\Rightarrow\begin{bmatrix}nx\\ny\\nz\\n\\\end{bmatrix}\)两个都表示同一个点透视投影:先将远截面按一定规则缩放到跟近截面一样大,然后再正交投影缩放规则:远截面缩放后\(z\)不变,缩放过后大小同近......
  • 打印数组中任意连续元素
    打印数组中任意连续元素1.例子#include<stdio.h>intmain(void){intarray[201];inti;for(i=0;i<201;i++)array[i]=i;return0;}在gdb中,如果要打印数组中任意连续元素的值,可以使用“parray[index]@num”命令(p是print命令的缩写)。其中index......