Motivated Motivated - 1 year ago 86
C# Question

Bind to property of object

I am currently developing a little musicplayer just for fun.
I was wondering if I can bind to a class named Track and access its propertys in XAML.

public class Track
public string TitleName { get; set; }
public BitmapImage Cover { get; set; }

Code can explain better than I can so here's my pseudo code:

<Image Source="{Binding BindingName="CurrentTrack" PropertyName="Cover"}"/>
<TextBlock Text="{Binding BindingName="CurrentTrack" PropertyName="Title"}"/>

Can I get something like this without using a Converter or sth like that ?

Answer Source

You can access a child property like this:

<TextBox Text="{Binding CurrentTrack.TitleName}"/>

You must have bound your View to your ViewModel

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download