How do I get find my “CheckBox” item that is in the ItemTemplate?

前端 未结 4 594
深忆病人
深忆病人 2020-12-29 04:12

I have the following (very simple) ItemsControl:


    
         


        
4条回答
  •  感情败类
    2020-12-29 05:00

    Here's an example of capturing a container that houses your ItemsControl's item:

           CheckBox checkbox = sender as CheckBox;
    
            foreach (var item in MembersItemsControl.Items)
            {
                var container = 
    MembersItemsControl.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
    
                UserInformation user = container.DataContext as UserInformation;
    
                bool isMale = true;
                if (user.sex == isMale && checkbox.IsChecked.Value == true)
                {
                    container.Visibility = System.Windows.Visibility.Visible;
                }
            }
    

    I hope that helps.

提交回复
热议问题