Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Binding to DataContext not Working

$
0
0

I have a wpf window that displays tasks.  The user clicks on a task in a TreeView control then other controls (TextBox, ComboBox, etc.) shows the various properties of the selected task.  I have implemented this as follows:

1) The TreeView is pupulated by:

ItemsSource="{Binding Source={StaticResource cvsTasks}}"

2) The DataContext for the window is set in code-behind as follows

Public Class Tasks
   Private tsk As Task
   ....
   Private Sub LoadMe(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      DataContext = tsk
	....
   End Sub	

   Private Sub SelectTask(sender As Object, e As RoutedPropertyChangedEventArgs(Of Object)) Handles treTasks.SelectedItemChanged
      tsk = DirectCast(e.NewValue, Task)
   End Sub
....
End Class

3) Each of the task properties using binding as shown below for the Description:

<TextBox
	x:Name="txtDescription"
	AcceptsReturn="True"
	Text="{Binding Path=Description}"></TextBox>
and that is what is not working.  None of the controls with binding show corresponding value when a TreeView item is selected by the user.

What an I doing wrong?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>