首页 > 其他分享 >WPF behavior InvokeCommndAction PassEventArgsToCommand

WPF behavior InvokeCommndAction PassEventArgsToCommand

时间:2024-09-20 11:23:22浏览次数:1  
标签:AddedItems obj eventArgs bk private PassEventArgsToCommand WPF null InvokeCommnd

//xaml
  <ListBox x:Name="lbx"
           SelectedIndex="0"
           ItemsSource="{Binding BooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
           VirtualizingPanel.IsContainerVirtualizable="True"
           VirtualizingPanel.IsVirtualizing="True"
           VirtualizingPanel.ScrollUnit="Item"
           VirtualizingPanel.VirtualizationMode="Recycling">
      <behavior:Interaction.Triggers>
          <behavior:EventTrigger EventName="SelectionChanged">               
              <behavior:InvokeCommandAction Command="{Binding SelectionChangedCmd}"
                                            PassEventArgsToCommand="True"/>
          </behavior:EventTrigger>
      </behavior:Interaction.Triggers>
</ListBox>


//cs
 private void InitCmds()
 {
     SelectionChangedCmd = new DelCmd(SelectionChangedCmdExecuted);
 }

 private void SelectionChangedCmdExecuted(object obj)
 {
     if(obj!=null)
     {
         var eventArgs = obj as SelectionChangedEventArgs;
         if(eventArgs!=null && eventArgs.AddedItems!=null && eventArgs.AddedItems.Count>0)
         {
             var bk = eventArgs.AddedItems[0] as Book;
             if(bk!=null)
             {
                 ImgTitle = bk.Name;
             }
         }
     }
 }

 

 

 

 

 

标签:AddedItems,obj,eventArgs,bk,private,PassEventArgsToCommand,WPF,null,InvokeCommnd
From: https://www.cnblogs.com/Fred1987/p/18422156

相关文章

  • WPF System.Windows.Media.Color A value must be set, display ball and number in c
    privateColorGetRndColor(){Colorcr=newColor();cr.A=255;cr.R=(byte)(rnd.Next(0,255));cr.G=(byte)(rnd.Next(0,255));cr.B=(byte)(rnd.Next(0,255));returncr;}         //usercontrol.......
  • WPF Customcontrol with ellipse and textblock display randomly in canvas of mainw
    //usercontrol.xaml<UserControlx:Class="WpfApp381.ElpImgTbk"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"......
  • WPF Element Width Height is percent of Parent element via converter ,converterpa
    //converterusingSystem;usingSystem.Collections.Generic;usingSystem.Globalization;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Data;namespaceWpfApp380{publicclassSizeConverter:IValueConverter......
  • WPF 异步
    在WPF中,异步编程非常重要,尤其是为了保持UI线程的响应性。由于WPF的UI操作必须在主线程上进行,耗时的任务(如文件读写、网络请求等)如果直接在UI线程上执行,会导致UI冻结,界面无法响应用户操作。因此,使用异步编程可以避免这些问题,使得任务能够在后台线程中执行,同时保持U......
  • C# + WPF 音频播放器 界面优雅,体验良好mL
    合集-.NET开源工具(17)1..NET开源快捷的数据库文档查询和生成工具07-312..NET结果与错误处理利器FluentResults08-013..NET+WPF桌面快速启动工具GeekDesk08-194.Gradio.NET支持.NET8简化Web应用开发08-265..NET开源实时监控系统-WatchDog08-276.实用接地气的.NE......
  • WPF 数据绑定之ValidationRule数据校验综合Demo
    一、概述我们利用ValidationRule以及ErrorTemplate来制作一个简单的表单验证。二、Demo核心思想:我们在ValidationRule中的Validate函数中进行验证,然后将验证结果存放至一个预先定义好的全局资源中,这样其他控件就可以根据验证结果来进行相应的处理,代码参见以下:usingSystem......
  • WPF ListBox ContextMenu MenuItem Command CommandParameter Path PlacementTarget
    <ListBox.ContextMenu><ContextMenu><MenuItemHeader="ExportNewtonSoftJson"FontSize="50"Foreground="Red"Command="{BindingExportNewt......
  • WPF ListBox ListBox use UserControl
    //usercontrolxaml<UserControlx:Class="WpfApp379.ImgTbk"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xml......
  • WPF Expander ExpandDirection Left,Right,Up,Down
    //xaml<Windowx:Class="WpfApp378.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • WPF WebBrowser suppress script errors
    ScriptError,Anerrorhasoccuredinthescriptonthispage.Doyouwanttocontinuerunningscriptsonthispage?   //xaml<Windowx:Class="WpfApp378.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/present......