【问题标题】:How to retrieve a list of all checked items in the listbox ? Silverlight WP7.1如何检索列表框中所有选中项目的列表?银光WP7.1
【发布时间】:2011-12-14 18:52:36
【问题描述】:

这是我的列表框,如何在代码隐藏中检索已检查的项目?

    <ListBox Name="AppointmentResultsData" ItemsSource="{Binding Path=Attendees}" Height="400"  ScrollViewer.ManipulationMode="Control" Margin="24,0,0,0" >
      <ListBox.ItemTemplate>
        <DataTemplate>
          <StackPanel>
            <CheckBox Content="{Binding Path=DisplayName, Mode=TwoWay}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
                      </StackPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>
    </ListBox>
<Button Content="Skicka" Click="SendPhoto_Click" HorizontalAlignment="Center" />

【问题讨论】:

    标签: silverlight xaml windows-phone-7 data-binding


    【解决方案1】:

    列表框是 IEnumerable。我还没有真正编译过这个,但是类似:

    var checked = AppointmentResultsData.ItemsSource.Where(i => i.IsChecked);
    

    【讨论】:

      【解决方案2】:

      检查是否能解决您的问题:

      How to get Selected items in WPF CheckBox ListBox

      通常建议使用视图模型方法。

      【讨论】:

      • 实际上,这是唯一合适的解决方案;-)
      • 如果您觉得有帮助,请记得标记答案,如果没有,请寻求进一步的支持
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      相关资源
      最近更新 更多