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;
    }

  • 相关阅读:
    HBase in Action前三章笔记
    关于视频YUV
    23种设计模式用英语怎样表达?
    UVA 10620
    工具,帮助我们更高效的工作
    VS下控制台执行保持(不要一闪而过)
    C语言之结构体
    Linux grep命令和正则表达式
    C#中的“静态”
    推荐一个计算机视觉图书:python计算机视觉编程
  • 原文地址:https://www.cnblogs.com/gnsds/p/3664746.html
Copyright © 2011-2022 走看看