E
E
Exvel2011-04-24 20:04:18
Domain Name System
Exvel, 2011-04-24 20:04:18

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

6 answer(s)
V
VenomBlood, 2011-04-24
@exvel

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.

D
Dmitry Sidorov, 2011-04-24
@Doomsday_nxt

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 ...

E
Exvel, 2011-04-24
@exvel

Tried like this:
/>
(This is my case)
After starting, the TextBlock is empty.

E
Exvel, 2011-04-24
@exvel

Parser ate. I tried something like this:
TextBlock Text="{Binding MainProgram.(Application.App).(LogService.Log).LastEntryText}" />

E
Exvel, 2011-04-24
@exvel

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.

E
Exvel, 2011-04-24
@exvel

Ugh. Okay it does not matter. I missed the line that you can set the DataContext for each object. Thank you, the issue has been resolved. :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question