code_junkie

Is there really no way to follow up dataset parent relation in xaml binding?

Nov 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <stackpanel> // with datacontext set from code to dataset.tables["ord"]
  2. <TextBox Text="{Binding Something}"/>
  3. <TextBox Text="{Binding Anotherthing}"/>
  4. <TextBox Text="{Binding ???}"/> // that's my problem, how to show related Emp.Name
  5. </stackpanel>
  6.  
  7. <StackPanel>
  8. <StackPanel.Resources>
  9. <ObjectDataProvider x:Key="ds" ObjectType="{x:Type mynamespace:MyDataSet}" />
  10. </StackPanel.Resources>
  11.  
  12. <!-- We set the data context to the collection of rows in the table -->
  13. <StackPanel DataContext="{Binding Source={StaticResource ds}, Path=USERS.Rows}">
  14. <ListBox ItemsSource="{Binding}"
  15. DisplayMemberPath="NAME"
  16. IsSynchronizedWithCurrentItem="True" />
  17. <TextBox Text="{Binding Path=NAME}"/>
  18. <TextBox Text="{Binding Path=COUNTRIESRow.NAME}"/>
  19. </StackPanel>
  20. </StackPanel>
  21.  
  22. using System.Data;
  23.  
  24. public partial class OrdDataTable : DataTable
  25. {
  26. public string EmpName
  27. {
  28. get { return this.EmpRow.Name; }
  29. }
  30. }
  31.  
  32. <TextBox Text="{Binding NAME}"/> //shows correctly current user's name
  33. <TextBox x:Name="tbC" Text="{Binding COUNTRIESRow.NAME}"/> //doesn't show related country name
  34.  
  35. tbC.Text = ds.USERS[0].COUNTRIESRow.NAME;
  36.  
  37. BindingExpression path error: 'COUNTRIESRow' property not found on 'object' 'USERSDataTable' (HashCode=6518513)'. BindingExpression:Path=COUNTRIESRow; DataItem='USERSDataTable' (HashCode=6518513); target element is 'TextBox' (Name='tbC'); target property is 'Text' (type 'String')
  38.  
  39. <StackPanel>
  40. <StackPanel.Resources>
  41. <ObjectDataProvider x:Key="ds" ObjectType="{x:Type mynamespace:MyDataSet}" />
  42. </StackPanel.Resources>
  43.  
  44. <!-- Notice we set the data context to the first item in the array of tables -->
  45. <StackPanel DataContext="{Binding Source={StaticResource ds}, Path=USERS[0]}">
  46. <TextBox Text="{Binding NAME}"/>
  47. <TextBox Text="{Binding COUNTRIESRow.NAME}"/>
  48. </StackPanel>
  49. </StackPanel>
Add Comment
Please, Sign In to add comment