0

Problem with binding SelectTask field. I checked in the debugger, the necessary information goes there through selecteditem, but for some reason in the stackpanel it does not want to bind...

public ObservableCollection<Task> Tasks { get; set; }
        public Task SelectTask { get; set; } 

        public MainWindowViewModel()
        {
            TabCollection = new ObservableCollection<object>();
            TabCollection.Add(new HomeViewModel() { TabName = "Main" });
            TabCollection.Add(new NewTaskViewModel() { TabName = "Add" });

            using (TaskContext db = new TaskContext())
            {
                Tasks = new ObservableCollection<Task>(db.Task);
            }
        }

 <ListBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="0"
                    SelectionMode="Extended"
                    ItemsSource="{Binding Tasks}"
                    SelectedItem="{Binding SelectTask}">
        </ListBox>

        <StackPanel DataContext="{Binding SelectTask}" HorizontalAlignment="Center" Grid.Column="1" Grid.Row="1">
            <Button Content="Удалить" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="74" />
            <Button Content="Редакт" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" />
            <UniformGrid  Columns="2">
                <TextBlock Text="Задача: " />
                <TextBlock Text ="{Binding Title}"  />
            </UniformGrid>
memento
  • 51
  • 5
  • 3
    SelectTask doesn't fire a change notification. You should implement INotifyPropertyChanged. – Clemens Jun 18 '20 at 12:01
  • Does this answer your question? [WPF binding not updating the view](https://stackoverflow.com/questions/25522218/wpf-binding-not-updating-the-view) – Sinatr Jun 18 '20 at 12:04

0 Answers0