Reputation: 2411
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;
Upvotes: 0
Views: 1863
Reputation: 78242
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}
Upvotes: 1