首页 > 其他分享 >WPF behavior InvokeCommandAction CommadParameter pass selectedItem of currentcontrol

WPF behavior InvokeCommandAction CommadParameter pass selectedItem of currentcontrol

时间:2024-09-20 11:46:14浏览次数:1  
标签:currentcontrol ImgTitle selectedItem private bk behavior pass WPF CommadParamete

 <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}"
                                           CommandParameter="{Binding Path=SelectedItem,
                 RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBox}}}"/>
         </behavior:EventTrigger>
     </behavior:Interaction.Triggers>
</ListBox>



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

private void SelectionChangedCmdExecuted(object obj)
{
    var bk = obj as Book;
    if (bk != null)
    {
        ImgTitle = bk.Name;
        MessageBox.Show(ImgTitle, "Image Title", MessageBoxButton.OK);
    }
}

 

 

 

 

 

 

 

标签:currentcontrol,ImgTitle,selectedItem,private,bk,behavior,pass,WPF,CommadParamete
From: https://www.cnblogs.com/Fred1987/p/18422189

相关文章

  • WPF behavior InvokeCommandAction CommandParameter
    <ListBoxx:Name="lbx"SelectedIndex="0"ItemsSource="{BindingBooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"VirtualizingPanel.IsContainerVirtualizable="True"......
  • WPF behavior InvokeCommndAction PassEventArgsToCommand
    //xaml<ListBoxx:Name="lbx"SelectedIndex="0"ItemsSource="{BindingBooksCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"VirtualizingPanel.IsContainerVirtualizable="Tru......
  • 注册表 ControlSet001、ControlSet002以及CurrentControlSet 详解
    注册表HKLM\system注意注册表项包含windows启动的三个控件组(额外还可能存在一个备份控件组)。在初始状态下。它们各自是ControlSet001、ControlSet002以及CurrentControlSet。这些控件组中包括了操作系统配置的信息,比方服务、驱动、系统控制、枚举信息等等。默认情况下,ControlSet......
  • 读论文《Behavior Pattern Mining-based Multi-Behavior Recommendation》
    论文地址:arxiv.org/pdf/2408.12152v1项目地址:GitHub-rookitkitlee/BPMR基于行为模式挖掘的多行为推荐:论文提出了一种新颖的多行为推荐算法(BPMR),旨在通过分析用户和项目之间的复杂交互模式来提高推荐系统的有效性。这种方法特别关注于用户除了购买之外的其他行为,例如页面浏览......
  • WPF KeyDown MVVM Via Behavior
    <behavior:Interaction.Triggers><behavior:EventTriggerEventName="KeyDown"><behavior:CallMethodActionMethodName="Window_KeyDown"TargetObject="{Binding}"/></behavior:EventTrigger>......
  • WPF KeyDown MVVM via CallMethodAction of behavior
    <behavior:Interaction.Triggers><behavior:EventTriggerEventName="KeyDown"><behavior:CallMethodActionMethodName="WinKeyDown"TargetObject="{Binding}"/></behavior:EventTrigger>&......
  • WPF DataGrid Checkbox column to implement select and unselect items explicitly v
    <DataGridTemplateColumnHeader="Select"><DataGridTemplateColumn.CellTemplate><DataTemplate><CheckBoxIsThreeState="False"><behavior:Interaction.Triggers>......
  • WPF ListBox's itemsource depend on another listbox's selecteditem
    //xaml<ListBoxGrid.Row="1"Grid.Column="0"ItemsSource="{Binding}"x:Name="countryLbx"DisplayMemberPath="CountryName"/><ListBoxGrid.Row="1"Grid.Column="1&......
  • Franka Robot setDefaultBehavior的作用
    Franka机器人的setDefaultBehavior()函数是一个非常有用的功能,它可以设置机器人在遇到意外情况时的默认行为。这个函数可以帮助开发者更好地控制机器人的安全性和稳定性。以下是setDefaultBehavior()函数的一些常见用法:安全停止行为可以设置机器人在遇到紧急情况时(如检测......
  • WPF MouseWheel MouseDown MouseUp MouseMove mapped in mvvm via behavior
    //xaml<Windowx:Class="WpfApp201.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......