1

と を持つ People というクラスがSTRING nameありSTRING ImgPathます。LIST listOfPeopleのソースであるを作りicCheckBoxます。

<DataTemplate x:Key="cBoxTemp">
        <StackPanel Orientation="Horizontal" Width="Auto" Height="Auto">
            <CheckBox Content="{Binding name}" MouseUp="CheckBox_MouseUp"/>                               
        </StackPanel>
    </DataTemplate>

xaml

<ItemsControl Name="icCheckBox" Grid.Column="0" ItemTemplate="{StaticResource cBoxTemp}" Height="Auto" Width="Auto">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Vertical"/>                                
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

チェックボックスが変更されるたびに調べて、チェックされている人の新しいリストを作成したいと思います。

private void CheckBox_MouseUp(object sender, MouseButtonEventArgs e)
    {
        //  listOfSelectedPeople = new List<Person>();
        //  For Each (Person e in listOfPeople)
        //  if(cur.isChecked == true)
        //     ListofSelectedPeople.add(current);
        //  ... Once I have this List populated my program will run
    }

isCheckedであるため、チェックボックスのプロパティを取得できませんdatatemplate。どうすればこれを行うことができますか?

4

3 に答える 3

0

EventToCommand を使用して Checked イベントをビュー モデルのコマンドにバインドし、現在の People オブジェクトをコマンド パラメーターで送信することをお勧めします。

<CheckBox...>
   <i:Interaction.Triggers>
       <i:EventTrigger EventName="Checked">
          <cmd:EventToCommand Command="{Binding PopulateCommad}"
                              CommandParameter="{Binding }"/>
      </i:EventTrigger>
   </i:Interaction.Triggers>
</CheckBox>

EventToCommand リファレンス

于 2013-07-12T20:10:36.230 に答える