zoukankan      html  css  js  c++  java
  • ListBox 绑定之-SelectedItem

    注意<i:Interaction>需要使用Blend的System.Windows.Interactivity.dll文件。

    通过<i:Interaction.Triggers> 关联到SelectionChanged事件,当前台获取到SelectedItem时,就会调用ViewModel的ExecuteGetItem方法,获取选择项。

    XAML:

    <ListBox ItemsSource="{Binding StandardSet,Mode=TwoWay}" SelectionMode="Single" Name="lb_items"
      Margin="0,0,0,125"
      >
      <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
        <i:InvokeCommandAction Command="{Binding GetItemCommand}"
          CommandParameter="{Binding ElementName=lb_items}"></i:InvokeCommandAction>
        </i:EventTrigger>
      </i:Interaction.Triggers>
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <WrapPanel ItemHeight="30" ItemWidth="100"></WrapPanel>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
      <ListBox.ItemTemplate>
        <DataTemplate>
          <ListBoxItem Content="{Binding Path=Standard.Name}"
            IsSelected="{Binding Path=IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
            >
          </ListBoxItem>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>

    ViewModel:

    public DelegateCommand<ListBox> GetItemCommand { get; set; }

    public void ExecuteGetItem(ListBox lb)
    {
      StandardViewModel model = lb.SelectedItem as StandardViewModel;
    }

  • 相关阅读:
    python requests用法总结
    Linux统计某文件夹下文件的个数
    PM2使用及介绍
    如何区分USB 2.0 和USB 3.0插口
    npm突然找不到npm-cli.js的解决方法
    mRemoteNG
    js中几种实用的跨域方法原理详解
    Tornado异步阻塞解决方案
    [阅读笔记]EfficientDet
    iOS 保存视频AVAssetWriter
  • 原文地址:https://www.cnblogs.com/gnsds/p/3664746.html
Copyright © 2011-2022 走看看