Answer the question
In order to leave comments, you need to log in
WPF: Data binding to a deeply nested property
Is it possible to bind a TexBlock to the property value of an object that is deeply nested using XAML?
For example, the TextBlock is in ProgramName.MainWindow and the bindable property is in ProgramName.App.Object1.Object2.Object3.Value.
In fact, I can't figure out how you can specify in XAML that an object is in a specific namespace.
Tried to play with DataContext and xmlns, but to no avail.
On the Internet, all examples are for simple binding options. :(
Answer the question
In order to leave comments, you need to log in
If you need to bind to a static object - I wrote above, if not to a static one (for example, via DataContext), then simply add the path:
<TextBox Text="{Binding Path=MyObject1.MyObject2.MyObject3.Name}"/>
Where Path is the path relative to the nearest DataContext object.
ProgramName.(AppType.App).(Object1Type.Object1).(Object2Type.Object2).(Object3Type.Object3).Value
Something like this, try it yourself ... Too lazy to check it yourself now, but it should look something like this ...
Tried like this:
/>
(This is my case)
After starting, the TextBlock is empty.
Parser ate. I tried something like this:
TextBlock Text="{Binding MainProgram.(Application.App).(LogService.Log).LastEntryText}" />
I don't quite understand what's going on here. If anything, my class is not static, and Log and App are objects.
I tried to write by analogy. I set this xmlns:
xmlns:log="clr-namespace:MainProgram.App.Log;assembly=MainProgram"
Writes: Unspecified CLR namespace. The "clr-namespace" URI refers to the "MainProgram.App.Log" namespace, which is not included in the assembly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question