Unfortunately there is no SelectedItem read/write dependency property for WPF. You can create a behaviour to get around this (
http://stackoverflow.com/questions/1000040/selecteditem-in-a-wpf-treeview[
^]), or use code behind for the SelectedItemChanged.
Ideally you should have a view model with an ItemsSource and SelectedItem property, and bind to each. The quick fix is to used the SelectedItemChanged event, and set the Text property of the TextBox to the Description of the new selected item:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeComponent();
Task job11 = new Task("JOB 1.1", "This is job 1.1");
Task job12 = new Task("JOB 1.2", "This is job 1.2");
Task job13 = new Task("JOB 1.3", "This is job 1.3");
Task job14 = new Task("JOB 1.4", "This is job 1.4");
Task MainTask = new Task("Main Job", new ObservableCollection<Task>(new List<Task> { job11, job12, job13, job14 }));
MainTask.Description = "This is my dear MAINTASK";
txtDescription.DataContext = MainTask;
treeTasks.Items.Add(MainTask);
treeTasks.FlowDirection = System.Windows.FlowDirection.RightToLeft;
treeTasks.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(treeTasks_SelectedItemChanged);
}
void treeTasks_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
var task = (Task) e.NewValue;
txtDescription.Text = task.Description;
}