2

I stuck in a Problem: I have a PopUp window, its DataContext points to an object which holds a reference to a ListBox (reftolistbox).

I managed to create a working binding with this codebehind code:

private void ID_Loaded(object sender, RoutedEventArgs e)
    {
        Binding myBinding = new Binding("id");
        myBinding.Source = ((myclass)DataContext).reftolistbox;
        myBinding.Path = new System.Windows.PropertyPath("SelectedItem.Name");
        BindingOperations.SetBinding(ID, ComboBox.TextProperty, myBinding);
    }

I want to replace the above code with a XAML Solution, here is a list i tried but no one worked.

<Combobox ...
     Text="{Binding Source=DataContext.reftolistbox, Path=SelectedItem.Name }"  
     Text="{Binding reftolistbox.SelectedItem.Name }"  
     Text="{Binding Path=DataContext.reftolistbox.SelectedItem.Name}"

Need a XAML Solution, what am I doing wrong?

StepUp
  • 36,391
  • 15
  • 88
  • 148
alexn234
  • 85
  • 1
  • 6

1 Answers1

0

XAML only binds to properties

DataContext:
              { public ListBox reftolistbox { get; set; } }

working binding in XAML:
              Text="{Binding reftolistbox.SelectedItem.Name }"  
alexn234
  • 85
  • 1
  • 6