Felix D.
Felix D.

Reputation: 5083

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:

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

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

Upvotes: 3

Views: 301

Answers (1)

Ryan Searle
Ryan Searle

Reputation: 1627

You can access a child property like this:

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

You must have bound your View to your ViewModel

Upvotes: 3

Related Questions