0

I've read up on binding to other classes but the syntax is tripping me up.

I have properties in my MainWindow.xaml.cs and I'd like to reference them SecondWindow.xaml.

I tried {Binding Source={x:Static local:MainWindow.Test}} but it complains about Key being null.

Update

Following the suggestion, I set the SecondWindow context to my MainWindow as well as tried setting the ParentHandle.

When the application runs, I get a bunch of runtime errors like this.

System.Windows.Data Error: 40 : BindingExpression path error: 'LabelColor' property not found on 'object' ''SecondWindow' (Name='secondWindow')'. BindingExpression:Path=LabelColor;

2
  • You should post the actual error/exception message Commented Feb 22, 2012 at 18:44
  • Check out this question... stackoverflow.com/questions/2037773/… Commented Feb 22, 2012 at 18:53

1 Answer 1

1

I think you can do something like this:

// I suppose MainWindow will new up an instance during some event. var window = new SecondWindow(); window.DataContext = this; // Set to MainWindow window.Show(); 

Then access it like this:

{Binding Test} 
Sign up to request clarification or add additional context in comments.

2 Comments

Ah interesting. Is it possible to have multiple data contexts so some can go to SecondWindow and others to MainWindow?
@Ternary I think you can only have one DataContext but with most controls you can set the ItemsSource and that control will ignore and DataContext from above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.