TextBox, Button and ListBox in a ListBox

前端 未结 3 1792
盖世英雄少女心
盖世英雄少女心 2020-12-17 07:41

I have a listbox with a bunch of contols in each list item.


    

        
3条回答
  •  一个人的身影
    2020-12-17 08:00

    This solution worked for the task at hand so to speak.

        private void ButtonAddNewTask_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            DependencyObject obj = LogicalTreeHelper.GetParent(button);
            StackPanel item = obj as StackPanel;
            TextBox textBox = item.FindName("textBoxTask") as TextBox;
            ListBox listBox = item.FindName("taskList") as ListBox;
    
            Project proj = button.DataContext as Project;
            if(proj.Tasks == null)
                proj.Tasks = new List();
    
            listBox.ItemsSource = proj.Tasks;
            listBox.Items.Refresh();
        }
    

提交回复
热议问题