0

i have a ResourceDictionary where i have this code:

<DataTemplate x:Key="UserDataTemplate">
        <StackPanel Orientation="Horizontal">
            <StackPanel>
                <Image Source="{Binding Path=MyPhoto}" Height="100"/>
                <Label HorizontalAlignment="Center" Content="{Binding Path=Names}"/>
            </StackPanel>
            <CheckBox x:Name="chkBxRegistered" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </StackPanel>        
    </DataTemplate>

in my xaml file i have:

<ItemsControl x:Name="UserList" ItemTemplate="{StaticResource UserDataTemplate}" Grid.Column="1">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>

and i bind my list on this way

UserList.ItemsSource = result; //List result so, in my code Behind i want to catch checked event and do all the logic i need or if anyone have another idea please comment and help me, thanks and sorry for my bad english .

1 Answers1

0

Considering I do not know how your xaml.cs looks like, the easiest way to solve this is to move the DataTemplate from ResourceDictionary to your xaml file (where you have ItemsControl defined) and then set Checked event handler on the CheckBox in DataTemplate.

Your modified DataTemplate would look like:

<DataTemplate x:Key="UserDataTemplate">
    <StackPanel Orientation="Horizontal">
        <StackPanel>
            <Image Source="{Binding Path=MyPhoto}" Height="100"/>
            <Label HorizontalAlignment="Center" Content="{Binding Path=Names}"/>
        </StackPanel>
        <CheckBox x:Name="chkBxRegistered" VerticalAlignment="Center" HorizontalAlignment="Center" Checked="ChkBxRegistered_OnChecked"/>
    </StackPanel>
</DataTemplate>

You can then write your checked handling logic in the event handler (in xaml.cs file):

private void ChkBxRegistered_OnChecked(object sender, RoutedEventArgs e)
{
    // Your checked handling code goes here
}
Suresh
  • 4,091
  • 28
  • 35