Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited title
Link
brunnerh
  • 188.1k
  • 30
  • 362
  • 434

Wpf Bind to Property in Another Class

added 400 characters in body
Source Link
Ternary
  • 2.4k
  • 4
  • 32
  • 54

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;

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.

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;

Source Link
Ternary
  • 2.4k
  • 4
  • 32
  • 54

Wpf Bind to Property in Another Class

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.